Skip to content

Commit b48dbd7

Browse files
committed
Merge pull request #30 from codegram/use-futuroscope
Use futuroscope to run API calls in the background
2 parents 09fbce2 + 4276241 commit b48dbd7

File tree

5 files changed

+88
-55
lines changed

5 files changed

+88
-55
lines changed

Gemfile.lock

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
GIT
22
remote: git://github.com/rubyworks/yard-tomdoc
3-
revision: caee83fb8b068fef81068e00dc8d1245354536f1
3+
revision: e4b09dcd574718bda91d0f956b4dd83246bda273
44
specs:
5-
yard-tomdoc (0.5.0)
6-
tomparse
5+
yard-tomdoc (0.7.1)
6+
tomparse (>= 0.4.0)
77
yard
88

99
PATH
@@ -12,66 +12,82 @@ PATH
1212
hyperclient (0.3.2)
1313
faraday (~> 0.8)
1414
faraday_middleware (~> 0.9)
15+
futuroscope (>= 0.0.10)
1516
net-http-digest_auth (~> 1.2)
1617
uri_template (~> 0.5)
1718

1819
GEM
1920
remote: https://rubygems.org/
2021
specs:
21-
addressable (2.2.8)
22-
ansi (1.4.2)
23-
coderay (1.0.6)
22+
addressable (2.3.4)
23+
ansi (1.4.3)
24+
coderay (1.0.9)
2425
colorize (0.5.8)
25-
crack (0.3.1)
26+
crack (0.3.2)
2627
faraday (0.8.8)
2728
multipart-post (~> 1.2.0)
2829
faraday_middleware (0.9.0)
2930
faraday (>= 0.7.4, < 0.9)
30-
ffi (1.0.11)
31-
gherkin-ruby (0.2.1)
31+
ffi (1.8.1)
32+
formatador (0.2.4)
33+
futuroscope (0.1.6)
34+
gherkin-ruby (0.3.0)
3235
growl (1.0.3)
33-
guard (1.0.3)
34-
ffi (>= 0.5.0)
36+
guard (1.8.0)
37+
formatador (>= 0.2.4)
38+
listen (>= 1.0.0)
39+
lumberjack (>= 1.0.2)
40+
pry (>= 0.9.10)
3541
thor (>= 0.14.6)
3642
guard-minitest (0.5.0)
3743
guard (>= 0.4)
38-
guard-spinach (0.0.1.1)
39-
guard
44+
guard-spinach (0.0.2)
45+
guard (>= 1.1)
4046
spinach
47+
listen (1.0.3)
48+
rb-fsevent (>= 0.9.3)
49+
rb-inotify (>= 0.9)
50+
rb-kqueue (>= 0.2)
51+
lumberjack (1.0.3)
4152
metaclass (0.0.1)
42-
method_source (0.7.1)
53+
method_source (0.8.1)
4354
minitest (3.4.0)
44-
mocha (0.13.1)
55+
mocha (0.13.3)
4556
metaclass (~> 0.0.1)
46-
multi_json (1.3.6)
57+
multi_json (1.7.2)
4758
multipart-post (1.2.0)
48-
net-http-digest_auth (1.2.1)
49-
pry (0.9.9.6)
59+
net-http-digest_auth (1.4)
60+
pry (0.9.12.1)
5061
coderay (~> 1.0.5)
51-
method_source (~> 0.7.1)
52-
slop (>= 2.4.4, < 3)
53-
rack (1.4.1)
62+
method_source (~> 0.8)
63+
slop (~> 3.4)
64+
rack (1.5.2)
5465
rack-test (0.6.2)
5566
rack (>= 1.0)
56-
rake (0.9.2.2)
57-
redcarpet (2.1.1)
58-
simplecov (0.6.4)
67+
rake (10.0.4)
68+
rb-fsevent (0.9.3)
69+
rb-inotify (0.9.0)
70+
ffi (>= 0.5.0)
71+
rb-kqueue (0.2.0)
72+
ffi (>= 0.5.0)
73+
redcarpet (2.2.2)
74+
simplecov (0.7.1)
5975
multi_json (~> 1.0)
60-
simplecov-html (~> 0.5.3)
61-
simplecov-html (0.5.3)
62-
slop (2.4.4)
63-
spinach (0.7.0)
64-
colorize
65-
gherkin-ruby (~> 0.2.0)
66-
thor (0.15.2)
67-
tomparse (0.2.1)
68-
turn (0.9.5)
76+
simplecov-html (~> 0.7.1)
77+
simplecov-html (0.7.1)
78+
slop (3.4.4)
79+
spinach (0.8.2)
80+
colorize (= 0.5.8)
81+
gherkin-ruby (~> 0.3.0)
82+
thor (0.18.1)
83+
tomparse (0.4.2)
84+
turn (0.9.6)
6985
ansi
70-
uri_template (0.5.1)
71-
webmock (1.8.7)
86+
uri_template (0.6.0)
87+
webmock (1.11.0)
7288
addressable (>= 2.2.7)
73-
crack (>= 0.1.7)
74-
yard (0.8.2.1)
89+
crack (>= 0.3.2)
90+
yard (0.8.6.1)
7591

7692
PLATFORMS
7793
ruby

hyperclient.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
1515
gem.version = Hyperclient::VERSION
1616

1717
gem.add_dependency 'faraday', '~> 0.8'
18+
gem.add_dependency 'futuroscope', '>= 0.0.10'
1819
gem.add_dependency 'faraday_middleware', '~> 0.9'
1920
gem.add_dependency 'uri_template', '~> 0.5'
2021
gem.add_dependency 'net-http-digest_auth', '~> 1.2'

lib/hyperclient/link.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'hyperclient/resource'
22
require 'uri_template'
3+
require 'futuroscope'
34

45
module Hyperclient
56
# Internal: The Link is used to let a Resource interact with the API.
@@ -100,31 +101,45 @@ def connection
100101
end
101102

102103
def get
103-
connection.get(url)
104+
Futuroscope::Future.new{
105+
connection.get(url)
106+
}
104107
end
105108

106109
def options
107-
connection.run_request(:options, url, nil, nil)
110+
Futuroscope::Future.new{
111+
connection.run_request(:options, url, nil, nil)
112+
}
108113
end
109114

110115
def head
111-
connection.head(url)
116+
Futuroscope::Future.new{
117+
connection.head(url)
118+
}
112119
end
113120

114121
def delete
115-
connection.delete(url)
122+
Futuroscope::Future.new{
123+
connection.delete(url)
124+
}
116125
end
117126

118127
def post(params = {})
119-
connection.post(url, params)
128+
Futuroscope::Future.new{
129+
connection.post(url, params)
130+
}
120131
end
121132

122133
def put(params = {})
123-
connection.put(url, params)
134+
Futuroscope::Future.new{
135+
connection.put(url, params)
136+
}
124137
end
125138

126139
def patch(params = {})
127-
connection.patch(url, params)
140+
Futuroscope::Future.new{
141+
connection.patch(url, params)
142+
}
128143
end
129144

130145
def inspect

test/hyperclient/link_test.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module Hyperclient
6161
it 'raises if no uri variables are given' do
6262
link = Link.new({'href' => '/orders{?id}', 'templated' => true}, entry_point)
6363

64-
proc { link.resource }.must_raise MissingURITemplateVariablesException
64+
proc { link.resource.url }.must_raise MissingURITemplateVariablesException
6565
end
6666
end
6767

@@ -119,7 +119,7 @@ module Hyperclient
119119
link = Link.new({'href' => '/productions/1'}, entry_point)
120120

121121
entry_point.connection.expects(:get).with('/productions/1')
122-
link.get
122+
link.get.inspect
123123
end
124124
end
125125

@@ -128,7 +128,7 @@ module Hyperclient
128128
link = Link.new({'href' => '/productions/1'}, entry_point)
129129

130130
entry_point.connection.expects(:run_request).with(:options, '/productions/1', nil, nil)
131-
link.options
131+
link.options.inspect
132132
end
133133
end
134134

@@ -137,7 +137,7 @@ module Hyperclient
137137
link = Link.new({'href' => '/productions/1'}, entry_point)
138138

139139
entry_point.connection.expects(:head).with('/productions/1')
140-
link.head
140+
link.head.inspect
141141
end
142142
end
143143

@@ -146,7 +146,7 @@ module Hyperclient
146146
link = Link.new({'href' => '/productions/1'}, entry_point)
147147

148148
entry_point.connection.expects(:delete).with('/productions/1')
149-
link.delete
149+
link.delete.inspect
150150
end
151151
end
152152

@@ -155,12 +155,12 @@ module Hyperclient
155155

156156
it 'sends a POST request with the link url and params' do
157157
entry_point.connection.expects(:post).with('/productions/1', {'foo' => 'bar'})
158-
link.post({'foo' => 'bar'})
158+
link.post({'foo' => 'bar'}).inspect
159159
end
160160

161161
it 'defaults params to an empty hash' do
162162
entry_point.connection.expects(:post).with('/productions/1', {})
163-
link.post
163+
link.post.inspect
164164
end
165165
end
166166

@@ -169,12 +169,12 @@ module Hyperclient
169169

170170
it 'sends a PUT request with the link url and params' do
171171
entry_point.connection.expects(:put).with('/productions/1', {'foo' => 'bar'})
172-
link.put({'foo' => 'bar'})
172+
link.put({'foo' => 'bar'}).inspect
173173
end
174174

175175
it 'defaults params to an empty hash' do
176176
entry_point.connection.expects(:put).with('/productions/1', {})
177-
link.put
177+
link.put.inspect
178178
end
179179
end
180180

@@ -183,12 +183,12 @@ module Hyperclient
183183

184184
it 'sends a PATCH request with the link url and params' do
185185
entry_point.connection.expects(:patch).with('/productions/1', {'foo' => 'bar'})
186-
link.patch({'foo' => 'bar'})
186+
link.patch({'foo' => 'bar'}).inspect
187187
end
188188

189189
it 'defaults params to an empty hash' do
190190
entry_point.connection.expects(:patch).with('/productions/1', {})
191-
link.patch
191+
link.patch.inspect
192192
end
193193
end
194194

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
$: << 'lib'
12
gem 'minitest'
23

34
require 'minitest/spec'

0 commit comments

Comments
 (0)