api_client 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/api_client.gemspec +18 -3
- data/lib/api_client/base.rb +2 -2
- data/lib/api_client/connection/middlewares/request/json.rb +2 -2
- data/lib/api_client/resource/base.rb +1 -1
- data/lib/api_client/version.rb +1 -1
- data/lib/api_client.rb +0 -1
- data/spec/api_client/base/instantiation_spec.rb +1 -1
- data/spec/api_client/connection/request/json_spec.rb +1 -1
- metadata +20 -7
- data/lib/api_client/resource/name_resolver.rb +0 -37
- data/spec/api_client/resource/name_spec.rb +0 -19
data/api_client.gemspec
CHANGED
@@ -18,18 +18,33 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.specification_version = 3
|
19
19
|
|
20
20
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
21
|
+
if RUBY_PLATFORM == "java"
|
22
|
+
s.add_runtime_dependency(%q<json_pure>)
|
23
|
+
else
|
24
|
+
s.add_runtime_dependency(%q<yajl-ruby>)
|
25
|
+
end
|
21
26
|
s.add_runtime_dependency(%q<faraday>, [">= 0.8.1"])
|
22
27
|
s.add_runtime_dependency(%q<hashie>, [">= 1.2.0"])
|
23
|
-
s.add_runtime_dependency(%q<
|
28
|
+
s.add_runtime_dependency(%q<multi_json>, [">= 1.6.1"])
|
24
29
|
else
|
30
|
+
if RUBY_PLATFORM == "java"
|
31
|
+
s.add_dependency(%q<json_pure>)
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<yajl-ruby>)
|
34
|
+
end
|
25
35
|
s.add_dependency(%q<faraday>, [">= 0.8.1"])
|
26
36
|
s.add_dependency(%q<hashie>, [">= 1.2.0"])
|
27
|
-
s.add_dependency(%q<
|
37
|
+
s.add_dependency(%q<multi_json>, [">= 1.6.1"])
|
28
38
|
end
|
29
39
|
else
|
40
|
+
if RUBY_PLATFORM == "java"
|
41
|
+
s.add_dependency(%q<json_pure>)
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<yajl-ruby>)
|
44
|
+
end
|
30
45
|
s.add_dependency(%q<faraday>, [">= 0.8.1"])
|
31
46
|
s.add_dependency(%q<hashie>, [">= 1.2.0"])
|
32
|
-
s.add_dependency(%q<
|
47
|
+
s.add_dependency(%q<multi_json>, [">= 1.6.1"])
|
33
48
|
end
|
34
49
|
|
35
50
|
s.files = `git ls-files`.split("\n")
|
data/lib/api_client/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "hashie"
|
2
|
-
require "
|
2
|
+
require "multi_json"
|
3
3
|
|
4
4
|
module ApiClient
|
5
5
|
|
@@ -25,7 +25,7 @@ module ApiClient
|
|
25
25
|
def parse(response)
|
26
26
|
response = response.body if response.is_a?(Faraday::Response)
|
27
27
|
if self.format == :json
|
28
|
-
|
28
|
+
MultiJson.load(response)
|
29
29
|
elsif self.format == :xml
|
30
30
|
MultiXml.parse(response)
|
31
31
|
else
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require "faraday"
|
2
|
-
require "
|
2
|
+
require "multi_json"
|
3
3
|
|
4
4
|
class ApiClient::Connection::Middlewares::Request::Json < Faraday::Middleware
|
5
5
|
CONTENT_TYPE = "Content-Type".freeze
|
@@ -12,7 +12,7 @@ class ApiClient::Connection::Middlewares::Request::Json < Faraday::Middleware
|
|
12
12
|
def call(env)
|
13
13
|
match_content_type(env) do |data|
|
14
14
|
params = Faraday::Utils::ParamsHash[data]
|
15
|
-
env[:body] =
|
15
|
+
env[:body] = MultiJson.dump(params)
|
16
16
|
end
|
17
17
|
@app.call env
|
18
18
|
end
|
data/lib/api_client/version.rb
CHANGED
data/lib/api_client.rb
CHANGED
@@ -23,7 +23,7 @@ describe ApiClient::Connection::Middlewares::Request::Json do
|
|
23
23
|
|
24
24
|
it "JSON encodes body" do
|
25
25
|
app.should_receive(:call).
|
26
|
-
with(hash_including(:body =>
|
26
|
+
with(hash_including(:body => MultiJson.dump(body)))
|
27
27
|
|
28
28
|
subject.call(env)
|
29
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,6 +11,22 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: faraday
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,13 +60,13 @@ dependencies:
|
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: 1.2.0
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
63
|
+
name: multi_json
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
49
65
|
none: false
|
50
66
|
requirements:
|
51
67
|
- - ! '>='
|
52
68
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
69
|
+
version: 1.6.1
|
54
70
|
type: :runtime
|
55
71
|
prerelease: false
|
56
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +74,7 @@ dependencies:
|
|
58
74
|
requirements:
|
59
75
|
- - ! '>='
|
60
76
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
77
|
+
version: 1.6.1
|
62
78
|
description: API client builder
|
63
79
|
email:
|
64
80
|
- marcin@futuresimple.com
|
@@ -96,7 +112,6 @@ files:
|
|
96
112
|
- lib/api_client/mixins/instantiation.rb
|
97
113
|
- lib/api_client/mixins/scoping.rb
|
98
114
|
- lib/api_client/resource/base.rb
|
99
|
-
- lib/api_client/resource/name_resolver.rb
|
100
115
|
- lib/api_client/resource/scope.rb
|
101
116
|
- lib/api_client/scope.rb
|
102
117
|
- lib/api_client/utils.rb
|
@@ -115,7 +130,6 @@ files:
|
|
115
130
|
- spec/api_client/connection/request/logger_spec.rb
|
116
131
|
- spec/api_client/connection/request/oauth_spec.rb
|
117
132
|
- spec/api_client/resource/base_spec.rb
|
118
|
-
- spec/api_client/resource/name_spec.rb
|
119
133
|
- spec/api_client/resource/scope_spec.rb
|
120
134
|
- spec/api_client/scope_spec.rb
|
121
135
|
- spec/api_client/utils_spec.rb
|
@@ -161,7 +175,6 @@ test_files:
|
|
161
175
|
- spec/api_client/connection/request/logger_spec.rb
|
162
176
|
- spec/api_client/connection/request/oauth_spec.rb
|
163
177
|
- spec/api_client/resource/base_spec.rb
|
164
|
-
- spec/api_client/resource/name_spec.rb
|
165
178
|
- spec/api_client/resource/scope_spec.rb
|
166
179
|
- spec/api_client/scope_spec.rb
|
167
180
|
- spec/api_client/utils_spec.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module ApiClient
|
2
|
-
module Resource
|
3
|
-
class NameResolver
|
4
|
-
def self.resolve(ruby_path)
|
5
|
-
new(ruby_path).resolve
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_reader :name
|
9
|
-
|
10
|
-
def initialize(name)
|
11
|
-
@name = name
|
12
|
-
end
|
13
|
-
|
14
|
-
def resolve
|
15
|
-
select_last_item
|
16
|
-
underscorize
|
17
|
-
lowercase
|
18
|
-
name
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
def select_last_item
|
23
|
-
@name = @name.split('::').last
|
24
|
-
end
|
25
|
-
|
26
|
-
#Inspired by ActiveSupport::Inflector#underscore
|
27
|
-
def underscorize
|
28
|
-
@name.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
29
|
-
@name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
30
|
-
end
|
31
|
-
|
32
|
-
def lowercase
|
33
|
-
@name.downcase!
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ApiClient::Resource::NameResolver do
|
4
|
-
describe '.resolve' do
|
5
|
-
subject { described_class }
|
6
|
-
|
7
|
-
it 'changes My::Namespace::MyResouce to my_resource' do
|
8
|
-
subject.resolve('My::Namespace::MyResource').should == 'my_resource'
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'changes Resource to resource' do
|
12
|
-
subject.resolve('Resource').should == 'resource'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'changes My::Resource to resoure' do
|
16
|
-
subject.resolve('My::Resource').should == 'resource'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|