sawyer 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sawyer/agent.rb +8 -6
- data/lib/sawyer/response.rb +5 -3
- data/lib/sawyer.rb +1 -1
- data/sawyer.gemspec +1 -1
- data/test/helper.rb +1 -1
- data/test/relation_test.rb +1 -1
- metadata +4 -4
data/lib/sawyer/agent.rb
CHANGED
@@ -29,9 +29,13 @@ module Sawyer
|
|
29
29
|
#
|
30
30
|
# endpoint - String URI of the API entry point.
|
31
31
|
# options - Hash of options.
|
32
|
-
# :
|
33
|
-
#
|
34
|
-
#
|
32
|
+
# :allow_undefined_methods - Allow relations to call all the HTTP verbs,
|
33
|
+
# not just the ones defined.
|
34
|
+
# :faraday - Optional Faraday::Connection to use.
|
35
|
+
# :links_parser - Optional parser to parse link relations
|
36
|
+
# Defaults: Sawyer::LinkParsers::Hal.new
|
37
|
+
# :serializer - Optional serializer Class. Defaults to
|
38
|
+
# self.serializer_class.
|
35
39
|
#
|
36
40
|
# Yields the Faraday::Connection if a block is given.
|
37
41
|
def initialize(endpoint, options = nil)
|
@@ -97,10 +101,8 @@ module Sawyer
|
|
97
101
|
end
|
98
102
|
started = Time.now
|
99
103
|
end
|
100
|
-
res.env[:sawyer_started] = started
|
101
|
-
res.env[:sawyer_ended] = Time.now
|
102
104
|
|
103
|
-
Response.new self, res
|
105
|
+
Response.new self, res, :sawyer_started => started, :sawyer_ended => Time.now
|
104
106
|
end
|
105
107
|
|
106
108
|
# Encodes an object to a string for the API request.
|
data/lib/sawyer/response.rb
CHANGED
@@ -10,13 +10,15 @@ module Sawyer
|
|
10
10
|
#
|
11
11
|
# agent - The Sawyer::Agent that is managing the API connection.
|
12
12
|
# res - A Faraday::Response.
|
13
|
-
def initialize(agent, res)
|
13
|
+
def initialize(agent, res, options = {})
|
14
14
|
@agent = agent
|
15
15
|
@status = res.status
|
16
16
|
@headers = res.headers
|
17
17
|
@env = res.env
|
18
18
|
@data = @headers[:content_type] =~ /json|msgpack/ ? process_data(@agent.decode_body(res.body)) : res.body
|
19
19
|
@rels = process_rels
|
20
|
+
@started = options[:sawyer_started]
|
21
|
+
@ended = options[:sawyer_ended]
|
20
22
|
end
|
21
23
|
|
22
24
|
# Turns parsed contents from an API response into a Resource or
|
@@ -48,11 +50,11 @@ module Sawyer
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def timing
|
51
|
-
@timing ||= @
|
53
|
+
@timing ||= @ended - @started
|
52
54
|
end
|
53
55
|
|
54
56
|
def time
|
55
|
-
@
|
57
|
+
@ended
|
56
58
|
end
|
57
59
|
|
58
60
|
def inspect
|
data/lib/sawyer.rb
CHANGED
data/sawyer.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.homepage = 'https://github.com/lostisland/sawyer'
|
18
18
|
spec.licenses = ['MIT']
|
19
19
|
|
20
|
-
spec.add_dependency 'faraday', ['~> 0.
|
20
|
+
spec.add_dependency 'faraday', ['~> 0.9.rc5']
|
21
21
|
spec.add_dependency 'uri_template', ['~> 0.5.0']
|
22
22
|
|
23
23
|
spec.files = %w(Gemfile LICENSE.md README.md Rakefile)
|
data/test/helper.rb
CHANGED
data/test/relation_test.rb
CHANGED
@@ -104,7 +104,7 @@ module Sawyer
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def test_relation_api_calls_with_uri_tempate
|
107
|
-
agent = Sawyer::Agent.new "http://foo.com/a
|
107
|
+
agent = Sawyer::Agent.new "http://foo.com/a" do |conn|
|
108
108
|
conn.builder.handlers.delete(Faraday::Adapter::NetHttp)
|
109
109
|
conn.adapter :test do |stubs|
|
110
110
|
stubs.get '/octocat/hello' do |env|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sawyer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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: 2013-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.9.rc5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: 0.9.rc5
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: uri_template
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|