kounta_rest 0.1.3 → 0.1.4

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.
@@ -36,7 +36,7 @@ module Kounta
36
36
 
37
37
  def initialize(hash={})
38
38
  if hash.empty?
39
- response = client.perform({:companies => "me"}, :get)
39
+ response = client.perform({:companies => "me"}, :get).parsed
40
40
  super(response)
41
41
  else
42
42
  super(hash)
@@ -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
- if response
65
- response.each_pair do |k,v|
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
@@ -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} (#{Oj.dump(options[:body], mode: :compat)})")
31
- response = @conn.request(request_method, "#{path_from_hash(url_hash)}.#{FORMAT.to_s}", options.merge(REQUEST_HEADERS))
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
- log("Response: #{response.parsed}")
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).map { |response| klass.new(response) }
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
- klass.new( perform(url_hash, request_method, options) )
64
+ response = perform(url_hash, request_method, options)
65
+ klass.new(response.parsed)
51
66
  end
52
67
 
53
68
  private
@@ -1,3 +1,3 @@
1
1
  module Kounta
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
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-13 00:00:00.000000000 Z
12
+ date: 2013-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler