Skip to content

Commit

Permalink
Added a test to url_request and updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
katylouise committed Apr 20, 2017
1 parent b8a1951 commit 3c9e889
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 366 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ gemspec

# Include coveralls for CI coverage reports
gem 'coveralls', require: false

gem 'parliament-grom-decorators', path: '../parliament-grom-decorators'
gem 'parliament-ntriple', path: '../parliament-ntriple'
2 changes: 0 additions & 2 deletions lib/parliament.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require 'net/http'
require 'grom'

require 'parliament/version'
require 'parliament/request'
require 'parliament/response'
require 'parliament/utils'
require 'parliament/builder'

require 'parliament/network_error'
Expand Down
8 changes: 4 additions & 4 deletions lib/parliament/builder/base_response_builder.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module Parliament
module Builder
# API response builder, allowing the user to return the body of an HTTPResponse.
# Base response builder, allowing the user to return the body of an HTTPResponse.
# @since 0.7.5
class BaseResponseBuilder
# Creates a new BaseReponseBuilder.
# @param [HTTPResponse] response an HTTP response containing n-triple data.
# @param [Module] decorators the decorator modules to provide alias methods to the resulting objects.
# @param [HTTPResponse] response an HTTP response.
# @param [Module] decorators a namespace which contains modules used to decorate the objects we receive. It is not used directly by the BaseResponseBuilder, but is there for API completeness.
def initialize(response:, decorators: nil)
@response = response
@decorators = decorators
_ = decorators
end

# Builds a Parliament::Response::BaseResponse.
Expand Down
10 changes: 8 additions & 2 deletions lib/parliament/request/base_request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Parliament
module Request
# API request object, allowing the user to make a request to an API.
# Base request object, allowing the user to make a request to an API.
#
# @since 0.7.5
#
Expand Down Expand Up @@ -65,15 +65,21 @@ def initialize(base_url: nil, headers: nil, builder: nil, decorators: nil)
#
# @example HTTP GET request
# request = Parliament::Request::BaseRequest.new(base_url: 'http://example.com/people/123'
#
# # url: http://example.com/people/123
#
# response = request.get #=> #<Parliament::Response::BaseResponse ...>
#
# @example HTTP GET request with URI encoded form values
# request = Parliament::Request.new(base_url: 'http://example.com/people/current')
#
# # url: http://example.com/people/current?limit=10&page=4&lang=en-gb
#
# response = request.get({ limit: 10, page: 4, lang: 'en-gb' }) #=> #<Parliament::Response::BaseResponse ...>
#
# @raise [Parliament::ServerError] when the server responds with a 5xx status code.
# @raise [Parliament::ClientError] when the server responds with a 4xx status code.
# @raise [Parliament::NoContentResponseError] when the server responds with a 204 status code.
# @raise [Parliament::NoContentResponseError] when the response body is empty.
#
# @param [Hash] params (optional) additional URI encoded form values to be added to the URI.
#
Expand Down
12 changes: 8 additions & 4 deletions lib/parliament/request/url_request.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Parliament
module Request
# API request object, allowing the user to build a request to an API.
# URL request object, allowing the user to build a URL to make a request to an API.
#
# @since 0.7.5
#
# @attr_reader [String] base_url the base url of our API. (expected: http://example.com - without the trailing slash).
# @attr_reader [String] base_url the endpoint for our API which we will build our requests on. (expected: http://example.com - without the trailing slash).
# @attr_reader [Hash] headers the headers being sent in the request.
class UrlRequest < Parliament::Request::BaseRequest
# Creates a new instance of Parliament::Request::UrlRequest.
Expand All @@ -14,7 +14,11 @@ class UrlRequest < Parliament::Request::BaseRequest
# @param [String] base_url the base url of our api. (expected: http://example.com - without the trailing slash).
# @param [Hash] headers the headers being sent in the request.
# @param [Parliament::Builder] builder the builder to use in order to build a response.
# @params [Module] decorators the decorator module to use in order to provide possible alias methods for any objects created by the builder.
# @param [Module] decorators the decorator module to use in order to provide possible alias methods for any objects created by the builder.
# @example Passing headers
#
# request = Parliament::Request::UrlRequest.new(base_url: 'http://example.com', headers: { 'Access-Token' => '12345678' })
# This will create a request with the Access-Token set to 12345678.
def initialize(base_url: nil, headers: nil, builder: nil, decorators: nil)
@endpoint_parts = []
base_url ||= ENV['PARLIAMENT_BASE_URL']
Expand Down Expand Up @@ -46,7 +50,7 @@ def initialize(base_url: nil, headers: nil, builder: nil, decorators: nil)
# @param [Array<Object>] params parameters passed to the specified method (url part).
# @param [Block] block additional block (kept for compatibility with method_missing API).
#
# @return [Parliament::Request::UrlRequest] self.
# @return [Parliament::Request::UrlRequest] self (this is to allow method chaining).
def method_missing(method, *params, &block)
@endpoint_parts << method.to_s
@endpoint_parts << params
Expand Down
135 changes: 0 additions & 135 deletions lib/parliament/utils.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/parliament/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Parliament
VERSION = '0.7.4'.freeze
VERSION = '0.7.5.pre'.freeze
end
3 changes: 1 addition & 2 deletions parliament-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ 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.3.6'

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', '~> 0.47'
spec.add_development_dependency 'simplecov', '~> 0.12'
spec.add_development_dependency 'vcr', '~> 3.0'
spec.add_development_dependency 'webmock', '~> 2.3'
spec.add_development_dependency 'parliament-grom-decorators'
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 3c9e889

Please sign in to comment.