Skip to content

Commit

Permalink
Merge pull request #2 from mattrayner/giusepped/grom-integration
Browse files Browse the repository at this point in the history
Integrate Grom into the gem
  • Loading branch information
mattrayner committed Jan 26, 2017
2 parents 35b1ab6 + 0d67fd9 commit e4b5667
Show file tree
Hide file tree
Showing 25 changed files with 1,402 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
/pkg/
/spec/reports/
/tmp/
*.gem

.idea
4 changes: 4 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ruby:
config_file: .rubocop.yml

fail_on_violations: true
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ sudo: false
language: ruby
rvm:
- 2.3.1
before_install: gem install bundler -v 1.13.7
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in parliament.gemspec
# Specify your gem's dependencies in parliament-ruby.gemspec
gemspec

# Include coveralls for CI coverage reports
gem 'coveralls', require: false
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Parliament Data API Wrapper (Ruby)
[parliament-ruby][parliament-ruby] is a gem created by the [Parliamentary Digital Service][pds] to allow easy communication with the internal parliament data api.

[![License][shield-license]][info-license]
[![Build Status][shield-travis]][info-travis] [![Test Coverage][shield-coveralls]][info-coveralls] [![License][shield-license]][info-license]

> **NOTE:** This gem is in active development and is likely to change at short notice. It is not recommended that you use this in any production environment.
Expand Down Expand Up @@ -128,5 +128,11 @@ If you wish to submit a bug fix or feature, you can create a pull request and it
[pds]: https://www.parliament.uk/mps-lords-and-offices/offices/bicameral/parliamentary-digital-service/
[ruby-version]: https://github.com/ukparliament/parliament-ruby/blob/master/.ruby-version

[info-travis]: https://travis-ci.org/ukparliament/parliament-ruby
[shield-travis]: https://img.shields.io/travis/ukparliament/parliament-ruby.svg

[info-coveralls]: https://coveralls.io/github/ukparliament/parliament-ruby
[shield-coveralls]: https://img.shields.io/coveralls/ukparliament/parliament-ruby.svg

[info-license]: http://www.parliament.uk/site-information/copyright/open-parliament-licence/
[shield-license]: https://img.shields.io/badge/license-Open%20Parliament%20Licence-blue.svg
2 changes: 2 additions & 0 deletions lib/parliament.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'pry'
require 'net/http'
require 'grom'

require 'parliament/version'
require 'parliament/request'
require 'parliament/response'

module Parliament
# Your code goes here...
Expand Down
7 changes: 6 additions & 1 deletion lib/parliament/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ def respond_to_missing?(method, include_private = false)
end

def get
Net::HTTP.get(URI(api_endpoint))
response = Net::HTTP.get_response(URI(api_endpoint))

raise StandardError, 'This is a HTTPClientError' if response.is_a?(Net::HTTPClientError)
raise StandardError, 'This is a HTTPServerError' if response.is_a?(Net::HTTPServerError)

Parliament::Response.new(Grom::Reader.new(response.body).objects)
end

private
Expand Down
29 changes: 29 additions & 0 deletions lib/parliament/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'forwardable'

module Parliament
class Response
include Enumerable
extend Forwardable
attr_reader :nodes
def_delegators :@nodes, :size, :each, :select, :map, :select!, :map!, :count, :length

def initialize(nodes)
@nodes = nodes
end

def filter(*types)
filtered_objects = Array.new(types.size) { [] }

unless types.empty?
@nodes.each do |node|
type_index = types.index(node.type)
filtered_objects[type_index] << node unless type_index.nil?
end
end

filtered_objects.each do |objects|
Parliament::Response.new(objects)
end
end
end
end
23 changes: 9 additions & 14 deletions parliament.gemspec → parliament-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'parliament/version'

Gem::Specification.new do |spec|
spec.name = 'parliament'
spec.name = 'parliament-ruby'
spec.version = Parliament::VERSION
spec.authors = ['Matt Rayner']
spec.email = ['mattrayner1@gmail.com']
Expand All @@ -13,14 +13,6 @@ Gem::Specification.new do |spec|
spec.homepage = 'http://github.com/ukparliament/parliament_ruby'
spec.license = 'Open Parliament License'

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = 'TODO: Set to \'http://mygemserver.com\''
else
raise 'RubyGems 2.0 or newer is required to protect against ' \
'public gem pushes.'
end

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
Expand All @@ -29,12 +21,15 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'grom', '~> 0.2.0'

spec.add_development_dependency 'bundler', '~> 1.13'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'vcr'
spec.add_development_dependency 'webmock'
spec.add_development_dependency 'rubocop', '~> 0.47.1'
spec.add_development_dependency 'pry', '~> 0.10.4'
spec.add_development_dependency 'pry-nav', '~> 0.2.4'
spec.add_development_dependency 'simplecov', '~> 0.12.0'
spec.add_development_dependency 'vcr', '~> 3.0.3'
spec.add_development_dependency 'webmock', '~> 2.3.2'
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e4b5667

Please sign in to comment.