ruby-iactionable 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +39 -0
- data/lib/iactionable/connection.rb +19 -19
- data/lib/iactionable/version.rb +1 -1
- data/ruby_iactionable.gemspec +3 -3
- data/spec/connection_spec.rb +11 -11
- metadata +16 -15
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruby-iactionable (0.1.1)
|
5
|
+
activesupport (>= 3.0.0)
|
6
|
+
faraday
|
7
|
+
faraday_middleware (~> 0.8.7)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (3.2.3)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
faraday (0.8.0)
|
17
|
+
multipart-post (~> 1.1)
|
18
|
+
faraday_middleware (0.8.7)
|
19
|
+
faraday (>= 0.7.4, < 0.9)
|
20
|
+
i18n (0.6.0)
|
21
|
+
multi_json (1.3.5)
|
22
|
+
multipart-post (1.1.5)
|
23
|
+
rspec (2.10.0)
|
24
|
+
rspec-core (~> 2.10.0)
|
25
|
+
rspec-expectations (~> 2.10.0)
|
26
|
+
rspec-mocks (~> 2.10.0)
|
27
|
+
rspec-core (2.10.0)
|
28
|
+
rspec-expectations (2.10.0)
|
29
|
+
diff-lcs (~> 1.1.3)
|
30
|
+
rspec-mocks (2.10.1)
|
31
|
+
yard (0.8.1)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
rspec (>= 2.6)
|
38
|
+
ruby-iactionable!
|
39
|
+
yard
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require '
|
2
|
+
require 'faraday_middleware'
|
3
3
|
require 'iactionable/error'
|
4
4
|
|
5
5
|
module IActionable
|
6
6
|
class Request < Struct.new(:path, :params, :headers, :body)
|
7
7
|
attr :settings
|
8
|
-
|
8
|
+
|
9
9
|
def initialize(settings)
|
10
10
|
@settings = settings
|
11
11
|
self.path = nil
|
@@ -13,51 +13,51 @@ module IActionable
|
|
13
13
|
self.headers = {}
|
14
14
|
self.body = {}
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def to(path)
|
18
18
|
self.path = path unless path.nil? || path.empty?
|
19
19
|
self
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def with_api_key
|
23
23
|
(self.headers[:Authorization] = @settings.api_key) and self
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def with_app_key
|
27
27
|
(self.params[:appKey] = @settings.app_key) and self
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def with_params(params={})
|
31
31
|
self.params.merge!(params) and self
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def with_body(body={})
|
35
35
|
self.body.merge!(body) and self
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
class Connection
|
40
40
|
attr :connection
|
41
41
|
attr :settings
|
42
42
|
attr :request
|
43
43
|
attr_accessor :response
|
44
|
-
|
44
|
+
|
45
45
|
def initialize(settings)
|
46
46
|
@settings = settings
|
47
|
-
|
47
|
+
|
48
48
|
@connection = Faraday.new api_url(@settings.version) do |builder|
|
49
|
-
builder.use
|
49
|
+
builder.use FaradayMiddleware::ParseJson, content_type: 'application/json'
|
50
50
|
builder.use Faraday::Response::RaiseError
|
51
51
|
builder.use Faraday::Adapter::NetHttp
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
@request = nil
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def request
|
58
58
|
(@request = Request.new(@settings)) and self
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def get(path=nil, query_params={})
|
62
62
|
@request ||= Request.new(@settings)
|
63
63
|
@request.to(path).with_params(query_params)
|
@@ -73,7 +73,7 @@ module IActionable
|
|
73
73
|
ensure
|
74
74
|
@request = nil
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def post(path=nil, query_params={}, body_params={})
|
78
78
|
@request ||= Request.new(@settings)
|
79
79
|
@request.to(path).with_params(query_params)
|
@@ -90,19 +90,19 @@ module IActionable
|
|
90
90
|
ensure
|
91
91
|
@request = nil
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
private
|
95
|
-
|
95
|
+
|
96
96
|
def method_missing(symbol, *args)
|
97
97
|
@request.send(symbol, *args) and self
|
98
98
|
rescue NoMethodError => e
|
99
99
|
raise e
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def api_url(version)
|
103
103
|
"http://api.iactionable.com/v#{version}/"
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
def handle_client_error(e)
|
107
107
|
# http://iactionable.com/api/response-codes/
|
108
108
|
case e.response[:status]
|
data/lib/iactionable/version.rb
CHANGED
data/ruby_iactionable.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib", "spec"]
|
20
20
|
|
21
|
-
|
21
|
+
|
22
22
|
s.add_development_dependency "rspec", ">= 2.6"
|
23
23
|
s.add_development_dependency "yard"
|
24
|
-
|
24
|
+
|
25
25
|
s.add_runtime_dependency "faraday"
|
26
|
-
s.add_runtime_dependency "
|
26
|
+
s.add_runtime_dependency "faraday_middleware", '~> 0.8.7'
|
27
27
|
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
28
28
|
end
|
data/spec/connection_spec.rb
CHANGED
@@ -9,20 +9,20 @@ describe IActionable::Connection do
|
|
9
9
|
}
|
10
10
|
@settings = IActionable::Settings.new(@settings_hash)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
describe "initialization" do
|
14
14
|
it "should initialize a new Faraday connection object" do
|
15
15
|
mock_faraday_bulder = mock("faraday builder")
|
16
|
-
|
16
|
+
|
17
17
|
Faraday.should_receive(:new).once.with("http://api.iactionable.com/v#{@settings.version}/").and_yield(mock_faraday_bulder)
|
18
|
-
mock_faraday_bulder.should_receive(:use).once.with(
|
18
|
+
mock_faraday_bulder.should_receive(:use).once.with(FaradayMiddleware::ParseJson, {:content_type => 'application/json'})
|
19
19
|
mock_faraday_bulder.should_receive(:use).once.with(Faraday::Response::RaiseError)
|
20
20
|
mock_faraday_bulder.should_receive(:use).once.with(Faraday::Adapter::NetHttp)
|
21
|
-
|
21
|
+
|
22
22
|
IActionable::Connection.new(@settings)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
describe "requests" do
|
27
27
|
before do
|
28
28
|
@mock_faraday_connection = mock("mock faraday connection")
|
@@ -37,7 +37,7 @@ describe IActionable::Connection do
|
|
37
37
|
@connection = IActionable::Connection.new(@settings)
|
38
38
|
@path = "/test/path"
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe "using get method" do
|
42
42
|
describe "requiring an app key" do
|
43
43
|
describe "with optional params" do
|
@@ -48,7 +48,7 @@ describe IActionable::Connection do
|
|
48
48
|
@connection.request.to(@path).with_app_key.with_params(:foo => :bar).get.should == @mock_response_body
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
describe "without optional params" do
|
53
53
|
it "should request correctly through faraday and return the body" do
|
54
54
|
@mock_faraday_connection.should_receive(:get).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
@@ -59,7 +59,7 @@ describe IActionable::Connection do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
describe "using post method" do
|
64
64
|
describe "requiring an app key" do
|
65
65
|
describe "requiring an api key" do
|
@@ -72,7 +72,7 @@ describe IActionable::Connection do
|
|
72
72
|
@connection.request.to(@path).with_app_key.with_api_key.with_params(:foo => :bar).post.should == @mock_response_body
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
describe "without optional params" do
|
77
77
|
it "should request correctly through faraday and return the body" do
|
78
78
|
@mock_faraday_connection.should_receive(:post).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
@@ -82,7 +82,7 @@ describe IActionable::Connection do
|
|
82
82
|
@connection.request.to(@path).with_app_key.with_api_key.post.should == @mock_response_body
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
describe "with an optional body" do
|
87
87
|
it "should request correctly through faraday and return the body" do
|
88
88
|
@mock_faraday_connection.should_receive(:post).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
@@ -93,7 +93,7 @@ describe IActionable::Connection do
|
|
93
93
|
@connection.request.to(@path).with_app_key.with_api_key.with_body(:foo => :bar).post.should == @mock_response_body
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
describe "without an optional body" do
|
98
98
|
it "should request correctly through faraday and return the body" do
|
99
99
|
@mock_faraday_connection.should_receive(:post).and_yield(@mock_faraday_request_builder).and_return(@mock_faraday_response)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-iactionable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2161584400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2161584400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: yard
|
27
|
-
requirement: &
|
27
|
+
requirement: &2161583940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2161583940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: faraday
|
38
|
-
requirement: &
|
38
|
+
requirement: &2161583480 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,21 +43,21 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2161583480
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement: &
|
48
|
+
name: faraday_middleware
|
49
|
+
requirement: &2161582960 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.8.7
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2161582960
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &2161582440 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 3.0.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2161582440
|
69
69
|
description: Ruby wrapper for IActionable's restful API.
|
70
70
|
email:
|
71
71
|
- ceberz@elctech.com
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- .rvmrc
|
78
78
|
- CHANGELOG.md
|
79
79
|
- Gemfile
|
80
|
+
- Gemfile.lock
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|
82
83
|
- lib/iactionable/api.rb
|