the86-client 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ require "addressable/uri"
1
2
  require "faraday"
2
3
  require "faraday_middleware"
3
4
 
@@ -44,7 +45,15 @@ module The86
44
45
 
45
46
  def dispatch(method, options)
46
47
  path = options.fetch(:path)
48
+ parameters = options[:parameters]
47
49
  data = options[:data]
50
+
51
+ if parameters
52
+ path = Addressable::URI.parse(path).tap do |uri|
53
+ uri.query_values = parameters
54
+ end.to_s
55
+ end
56
+
48
57
  headers = @faraday.headers.merge(options[:headers] || {})
49
58
  response = @faraday.run_request(method, path, data, headers)
50
59
  assert_http_status(response, options[:status])
@@ -27,6 +27,14 @@ module The86::Client
27
27
  build(attributes).tap(&:save)
28
28
  end
29
29
 
30
+ attr_writer :parameters
31
+
32
+ def with_parameters(parameters)
33
+ dup.tap do |collection|
34
+ collection.parameters = parameters
35
+ end
36
+ end
37
+
30
38
  # Find and load a resource.
31
39
  #
32
40
  # If Resource#url_id is overridden, specify the attribute name.
@@ -59,7 +67,11 @@ module The86::Client
59
67
  private
60
68
 
61
69
  def records
62
- @records ||= @connection.get(path: @path, status: 200)
70
+ @records ||= @connection.get(
71
+ path: @path,
72
+ parameters: @parameters,
73
+ status: 200
74
+ )
63
75
  end
64
76
 
65
77
  end
@@ -1,5 +1,5 @@
1
1
  module The86
2
2
  module Client
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -23,6 +23,19 @@ module The86::Client
23
23
  c.id.must_equal 10
24
24
  c.site.must_equal site
25
25
  end
26
+
27
+ it "sends posts_since parameter" do
28
+ expect_get_conversations(
29
+ response_body: [{id: 10}, {id: 12}],
30
+ parameters: {posts_since: "time"}
31
+ )
32
+ conversations = site.conversations.with_parameters(posts_since: "time")
33
+ conversations.to_a.size.must_equal 2
34
+ c = conversations.first
35
+ c.must_be_instance_of Conversation
36
+ c.id.must_equal 10
37
+ c.site.must_equal site
38
+ end
26
39
  end
27
40
 
28
41
  describe "creating conversations" do
@@ -1,3 +1,4 @@
1
+ require "addressable/uri"
1
2
  require "json"
2
3
  require "webmock/minitest"
3
4
 
@@ -22,11 +23,18 @@ module RequestExpectations
22
23
  rack_method_override!(options, :patch)
23
24
 
24
25
  url = options.fetch(:url)
26
+ parameters = options[:parameters]
25
27
  method = options.fetch(:method)
26
28
  request_body = options[:request_body]
27
29
  response_body = options[:response_body]
28
30
  request_headers = options[:request_headers]
29
31
 
32
+ if parameters
33
+ url = Addressable::URI.parse(url).tap do |url|
34
+ url.query_values = parameters
35
+ end.to_s
36
+ end
37
+
30
38
  request = {}
31
39
  request[:body] = request_body if request_body
32
40
  request[:headers] = request_headers if request_headers
data/the86-client.gemspec CHANGED
@@ -23,6 +23,9 @@ Gem::Specification.new do |gem|
23
23
  gem.add_runtime_dependency "faraday_middleware"
24
24
  gem.add_runtime_dependency "hashie"
25
25
 
26
+ # Addressable: URI implementation.
27
+ gem.add_runtime_dependency "addressable"
28
+
26
29
  # Virtus: declare attributes on plain Ruby objects.
27
30
  gem.add_runtime_dependency "virtus"
28
31
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the86-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: addressable
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: virtus
64
80
  requirement: !ruby/object:Gem::Requirement