octobat 0.0.10 → 0.0.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22df9f164500e5d3c1909f3f351cf4ebf29645e7
4
- data.tar.gz: db2e51a3201c34aeb49fc2245fe43c6d33b9d597
3
+ metadata.gz: 13b23c6576b35201a486ec9872311bd2858a1b64
4
+ data.tar.gz: f1a6871a5e86bd4eff0db246d1c43cd74cdb5bc2
5
5
  SHA512:
6
- metadata.gz: 9e0faf31f3489cf4094e154d420d9d2cbf4b7af6fb1e007734d10ed850c554e6cf28e7566bf21b4c929d27e24dd38bef11a9b21fd0549e6624fcd9fc15cf6f7e
7
- data.tar.gz: 2467300f9b287e504742a82d02181f0f8a9a4a2938d4532c1a334f27aa6fa4b8f4d61f3121d5305a4daad4594f8cec72140034656d6be6151b8617a8bd48e723
6
+ metadata.gz: 24bf2a0ad0294d35d50b966f2eb11791521f43c3677d7f35ce12e2f265bb873b6465c822862599033fd84150064f94cb5e9df834bcea7758cbc82a827a6076b9
7
+ data.tar.gz: 981c7c5611340661a0aec31549c8e71deab45887344bc79de429bbec2b4713b9de7e5079e8be124f91e7175d3b2068d94431017d30871f13957aa99fa5b5dc16
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- octobat (0.0.10)
4
+ octobat (0.0.11)
5
5
  json (~> 1.8.1)
6
6
  mime-types (>= 1.25, < 3.0)
7
7
  rest-client (~> 1.4)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -1,17 +1,25 @@
1
1
  module Octobat
2
2
  module APIOperations
3
3
  module List
4
- module ClassMethods
5
- def all(filters={}, opts={})
6
- api_key, headers = Util.parse_opts(opts)
7
- response, api_key = Octobat.request(:get, url, api_key, filters, headers)
8
- Util.convert_to_octobat_object(response, api_key)
9
- end
10
- end
11
-
12
- def self.included(base)
13
- base.extend(ClassMethods)
4
+ def list(filters={}, opts={})
5
+ api_key, headers = Util.parse_opts(opts)
6
+ api_key ||= @api_key
7
+
8
+ #opts = Util.normalize_opts(opts)
9
+ #opts = @opts.merge(opts) if @opts
10
+
11
+ response, api_key = Octobat.request(:get, url, api_key, filters, headers)
12
+ obj = ListObject.construct_from(response, api_key)
13
+
14
+ obj.filters = filters.dup
15
+ obj.cursors[:ending_before] = obj.filters.delete(:ending_before)
16
+ obj.cursors[:starting_after] = obj.filters.delete(:starting_after)
17
+
18
+
19
+ obj
14
20
  end
21
+
22
+ alias :all :list
15
23
  end
16
24
  end
17
25
  end
@@ -1,5 +1,5 @@
1
1
  module Octobat
2
2
  class CreditNoteNumberingSequence < APIResource
3
- include Octobat::APIOperations::List
3
+ extend Octobat::APIOperations::List
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  module Octobat
2
2
  class Customer < APIResource
3
- include Octobat::APIOperations::List
3
+ extend Octobat::APIOperations::List
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Octobat
2
2
  class Invoice < APIResource
3
- include Octobat::APIOperations::List
3
+ extend Octobat::APIOperations::List
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
 
@@ -1,5 +1,15 @@
1
1
  module Octobat
2
2
  class ListObject < OctobatObject
3
+ include Enumerable
4
+ include Octobat::APIOperations::List
5
+
6
+ attr_accessor :filters, :cursors
7
+
8
+ def initialize(*args)
9
+ super
10
+ self.filters = {}
11
+ self.cursors = {}
12
+ end
3
13
 
4
14
  def [](k)
5
15
  case k
@@ -13,10 +23,14 @@ module Octobat
13
23
  def each(&blk)
14
24
  self.data.each(&blk)
15
25
  end
26
+
27
+ def empty?
28
+ self.data.empty?
29
+ end
16
30
 
17
31
  def retrieve(id, api_key=nil)
18
32
  api_key ||= @api_key
19
- response, api_key = Octobat.request(:get,"#{url}/#{CGI.escape(id)}", api_key)
33
+ response, api_key = Octobat.request(:get, "#{url}/#{CGI.escape(id)}", api_key)
20
34
  Util.convert_to_octobat_object(response, api_key)
21
35
  end
22
36
 
@@ -27,11 +41,25 @@ module Octobat
27
41
  Util.convert_to_octobat_object(response, api_key)
28
42
  end
29
43
 
30
- def all(params={}, opts={})
31
- api_key, headers = Util.parse_opts(opts)
32
- api_key ||= @api_key
33
- response, api_key = Octobat.request(:get, url, api_key, params, headers)
34
- Util.convert_to_octobat_object(response, api_key)
44
+
45
+ def next_page_params(params={}, opts={})
46
+ return nil if !has_more
47
+ last_id = data.last.id
48
+
49
+ params = filters.merge({
50
+ starting_after: last_id
51
+ }).merge(params)
52
+ end
53
+
54
+
55
+ def previous_page_params(params={}, opts={})
56
+ return nil if cursors[:starting_after].nil? || cursors[:starting_after].empty?
57
+ first_id = data.first.id
58
+
59
+ params = filters.merge({
60
+ ending_before: first_id
61
+ }).merge(params)
35
62
  end
63
+
36
64
  end
37
65
  end
@@ -1,5 +1,5 @@
1
1
  module Octobat
2
2
  class NumberingSequence < APIResource
3
- include Octobat::APIOperations::List
3
+ extend Octobat::APIOperations::List
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  module Octobat
2
2
  class PaymentMode < APIResource
3
- include Octobat::APIOperations::List
3
+ extend Octobat::APIOperations::List
4
4
  include Octobat::APIOperations::Create
5
5
  include Octobat::APIOperations::Update
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module Octobat
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octobat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaultier Laperche
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client