kounta_rest 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kounta/company.rb +1 -1
- data/lib/kounta/resource.rb +2 -4
- data/lib/kounta/rest/client.rb +22 -7
- data/lib/kounta/version.rb +1 -1
- metadata +2 -2
data/lib/kounta/company.rb
CHANGED
data/lib/kounta/resource.rb
CHANGED
@@ -61,10 +61,8 @@ module Kounta
|
|
61
61
|
|
62
62
|
def save!
|
63
63
|
response = new? ? client.perform(resource_path, :post, {:body => to_hash}) : client.perform(resource_path, :put, {:body => to_hash})
|
64
|
-
|
65
|
-
|
66
|
-
self[k] = v
|
67
|
-
end
|
64
|
+
response.parsed.each_pair do |k,v|
|
65
|
+
self[k] = v
|
68
66
|
end
|
69
67
|
self
|
70
68
|
end
|
data/lib/kounta/rest/client.rb
CHANGED
@@ -26,9 +26,12 @@ module Kounta
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def perform(url_hash, request_method, options={})
|
29
|
+
options[:headers] ||= {}
|
30
|
+
options[:headers].merge!(Kounta::REQUEST_HEADERS)
|
31
|
+
|
29
32
|
begin
|
30
|
-
log("#{request_method}: #{Kounta::SITE_URI}#{path_from_hash(url_hash)}.#{FORMAT.to_s}
|
31
|
-
response = @conn.request(request_method, "#{path_from_hash(url_hash)}.#{FORMAT.to_s}", options
|
33
|
+
log("#{request_method}: #{Kounta::SITE_URI}#{path_from_hash(url_hash)}.#{FORMAT.to_s}")
|
34
|
+
response = @conn.request(request_method, "#{path_from_hash(url_hash)}.#{FORMAT.to_s}", options)
|
32
35
|
rescue OAuth2::Error => ex
|
33
36
|
if ex.message.include? 'The access token provided has expired'
|
34
37
|
log(ex.message)
|
@@ -37,17 +40,29 @@ module Kounta
|
|
37
40
|
end
|
38
41
|
raise Kounta::Errors::APIError.new(ex.message)
|
39
42
|
end
|
40
|
-
|
41
|
-
|
42
|
-
response.parsed
|
43
|
+
|
44
|
+
response
|
43
45
|
end
|
44
46
|
|
45
47
|
def objects_from_response(klass, request_method, url_hash, options={})
|
46
|
-
perform(url_hash, request_method, options)
|
48
|
+
response = perform(url_hash, request_method, options)
|
49
|
+
page_count = response.headers["x-pages"].to_i
|
50
|
+
|
51
|
+
if page_count > 1
|
52
|
+
results = []
|
53
|
+
page_count.times { |page_number|
|
54
|
+
response = perform(url_hash, request_method, options.merge!(:headers => {'X-Page' => (page_number).to_s}))
|
55
|
+
results = results + response.parsed
|
56
|
+
}
|
57
|
+
results.map { |item| klass.new(item) }
|
58
|
+
else
|
59
|
+
response.parsed.map { |item| klass.new(item) }
|
60
|
+
end
|
47
61
|
end
|
48
62
|
|
49
63
|
def object_from_response(klass, request_method, url_hash, options={})
|
50
|
-
|
64
|
+
response = perform(url_hash, request_method, options)
|
65
|
+
klass.new(response.parsed)
|
51
66
|
end
|
52
67
|
|
53
68
|
private
|
data/lib/kounta/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kounta_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-11-
|
12
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|