barge 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61432518c68ce3048755a40556dc53afdc00b3f4
4
- data.tar.gz: 83ad99d33eebc187912e45547edbdfe59b8952b5
3
+ metadata.gz: a580428f182b00e938e6b137ca19d27f875be4ad
4
+ data.tar.gz: 6fd36010dac884e132d4d137de028a140a5c2091
5
5
  SHA512:
6
- metadata.gz: b9f72efc66ce4041203e6086d8b5159f726b1cc1c54593a2c7ed5d6399597903092d1e5de6f5e7777732b6d2430502a2a8d8d8dd723f0b2c15919c1efb569b23
7
- data.tar.gz: 659a25b05ae7b778294e692300c8f02e81d08ab0f88f320919c7bc06bdd7c3cedf238ce4ff22efa95a49e56bafa46b8325db69c27193fbe2eaf76bc2212f1b8e
6
+ metadata.gz: 7a7cb726892362d9d833f2f07d715ffd80f3eb68297f1a2c96da717438c322fb63b1105e39175803c3186834c1b12e342436f755109007956d56e97d97aa382e
7
+ data.tar.gz: 06d0c6b59f05acad0f15c76c5981f2cb3479e085c689c389398ad17bc6b3edf1f2ce2b53863d5c413d371d05d93a2b9f669911fc2e8ea19f69c42d0544635272
data/README.md CHANGED
@@ -55,9 +55,9 @@ can be accessed using dot notation:
55
55
 
56
56
  ``` ruby
57
57
  droplet = barge.droplet.show(droplet_id)
58
- droplet.name # => "foo"
59
- droplet.image.id # => 123
60
- droplet.size!.vcpus # => 1
58
+ droplet.droplet.name # => "foo"
59
+ droplet.droplet.image.id # => 123
60
+ droplet.droplet.size!.vcpus # => 1
61
61
  ```
62
62
 
63
63
  Notice that `size!` and not `size` was used. This is because `size` already is
@@ -65,10 +65,17 @@ a method, and Hashie::Mash will not override it. You can also use square
65
65
  brackets:
66
66
 
67
67
  ``` ruby
68
- droplet[:size][:vcpus] # => 1
69
- droplet['size']['vcpus'] # => 1
68
+ droplet[:droplet][:size][:vcpus] # => 1
69
+ droplet['droplet']['size']['vcpus'] # => 1
70
70
  ```
71
71
 
72
+ See the [API documentation on responses][api-responses] if you are wondering
73
+ why attributes are contained within a `droplet` key. This might change when
74
+ pagination is fully implemented so you can say for instance `droplet.name`
75
+ instead.
76
+
77
+ [api-responses]: https://developers.digitalocean.com/#responses
78
+
72
79
  ### success?
73
80
 
74
81
  You can use `success?` to check if a successful HTTP status code was returned:
@@ -77,6 +84,56 @@ You can use `success?` to check if a successful HTTP status code was returned:
77
84
  barge.droplet.create(options).success? # => true
78
85
  ```
79
86
 
87
+ ### response
88
+
89
+ Barge uses [Faraday][faraday]. You can use `response` to get to the response
90
+ object:
91
+
92
+ ``` ruby
93
+ barge.droplet.show(droplet_id).response # => Faraday::Response
94
+ ```
95
+
96
+ [faraday]: https://github.com/lostisland/faraday
97
+
98
+ Pagination
99
+ ----------
100
+
101
+ For [paginated resources][api-links], a maximum of 200 objects are returned by
102
+ default (the maximum allowed by the API).
103
+
104
+ ### Limit objects per page and/or get a specific page
105
+
106
+ ``` ruby
107
+ barge.image.all(per_page: 10, page: 2)
108
+ ```
109
+
110
+ [api-links]: https://developers.digitalocean.com/#links
111
+
112
+ ### Check if a response is paginated
113
+
114
+ ``` ruby
115
+ barge.action.all.paginated? # => true
116
+ barge.region.all.paginated? # => false
117
+ ```
118
+
119
+ ### Get the previous page number
120
+
121
+ ``` ruby
122
+ barge.image.all(per_page: 5, page: 2).prev_page # => 1
123
+ ```
124
+
125
+ ### Get the next page number
126
+
127
+ ``` ruby
128
+ barge.image.all(per_page: 5, page: 2).next_page # => 3
129
+ ```
130
+
131
+ ### Get the last page number
132
+
133
+ ``` ruby
134
+ barge.image.all(per_page: 5, page: 2).last_page # => 8
135
+ ```
136
+
80
137
  Action
81
138
  ------
82
139
 
@@ -2,6 +2,7 @@ require 'hashie'
2
2
 
3
3
  require 'barge/client'
4
4
  require 'barge/resource'
5
+ require 'barge/response'
5
6
  require 'barge/version'
6
7
 
7
8
  module Barge
@@ -3,8 +3,8 @@ module Barge
3
3
  class Action
4
4
  include Resource::Base
5
5
 
6
- def all
7
- get('actions')
6
+ def all(options = {})
7
+ get('actions', options)
8
8
  end
9
9
 
10
10
  def show(action_id)
@@ -3,7 +3,7 @@ module Barge
3
3
  module Base
4
4
  attr_reader :faraday
5
5
 
6
- PER_PAGE = 999
6
+ PER_PAGE = 200
7
7
 
8
8
  def initialize(faraday)
9
9
  @faraday = faraday
@@ -17,13 +17,9 @@ module Barge
17
17
  end
18
18
  end
19
19
 
20
- def request(verb, *args)
21
- options = { per_page: PER_PAGE } if verb == :get
22
- response = faraday.public_send(verb, *args, options)
23
- response.body.tap do |r|
24
- r.define_singleton_method(:response) { response }
25
- r.define_singleton_method(:success?) { response.success? }
26
- end
20
+ def request(verb, path, options = {})
21
+ options = { per_page: PER_PAGE }.merge(options) if verb == :get
22
+ Response.new faraday.public_send(verb, path, options)
27
23
  end
28
24
  end
29
25
  end
@@ -7,8 +7,8 @@ module Barge
7
7
  post('domains', options.to_json)
8
8
  end
9
9
 
10
- def all
11
- get('domains')
10
+ def all(options = {})
11
+ get('domains', options)
12
12
  end
13
13
 
14
14
  def show(domain_name)
@@ -23,8 +23,8 @@ module Barge
23
23
  post("domains/#{domain_name}/records", options.to_json)
24
24
  end
25
25
 
26
- def records(domain_name)
27
- get("domains/#{domain_name}/records")
26
+ def records(domain_name, options = {})
27
+ get("domains/#{domain_name}/records", options)
28
28
  end
29
29
 
30
30
  def show_record(domain_name, record_id)
@@ -7,8 +7,8 @@ module Barge
7
7
  post('droplets', options.to_json)
8
8
  end
9
9
 
10
- def all
11
- get('droplets')
10
+ def all(options = {})
11
+ get('droplets', options)
12
12
  end
13
13
 
14
14
  def show(droplet_id)
@@ -3,8 +3,8 @@ module Barge
3
3
  class Image
4
4
  include Resource::Base
5
5
 
6
- def all
7
- get('images')
6
+ def all(options = {})
7
+ get('images', options)
8
8
  end
9
9
 
10
10
  def show(image_id)
@@ -0,0 +1,38 @@
1
+ require 'forwardable'
2
+
3
+ module Barge
4
+ class Response < Hashie::Mash
5
+ extend Forwardable
6
+
7
+ attr_reader :response
8
+ def_delegator :response, :success?, :success?
9
+
10
+ def initialize(faraday_response)
11
+ @response = faraday_response
12
+ super(faraday_response.body)
13
+ end
14
+
15
+ def paginated?
16
+ !(links && links.pages).nil?
17
+ end
18
+
19
+ def prev_page
20
+ extract_page(:prev)
21
+ end
22
+
23
+ def next_page
24
+ extract_page(:next)
25
+ end
26
+
27
+ def last_page
28
+ extract_page(:last)
29
+ end
30
+
31
+ private
32
+
33
+ def extract_page(key)
34
+ return unless paginated? && links.pages.key?(key)
35
+ Integer links.pages[key][/page=(\d+)/, 1]
36
+ end
37
+ end
38
+ end
@@ -1,7 +1,7 @@
1
1
  module Barge
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 7
4
+ MINOR = 8
5
5
  PATCH = 0
6
6
 
7
7
  def self.to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Ørjan Blom"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-03 00:00:00.000000000 Z
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.1'
47
+ version: '3.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.1'
54
+ version: '3.2'
55
55
  description: Ruby library for version 2 of DigitalOcean's API
56
56
  email:
57
57
  - blom@blom.tv
@@ -73,6 +73,7 @@ files:
73
73
  - lib/barge/resource/key.rb
74
74
  - lib/barge/resource/region.rb
75
75
  - lib/barge/resource/size.rb
76
+ - lib/barge/response.rb
76
77
  - lib/barge/version.rb
77
78
  homepage: https://github.com/boats/barge
78
79
  licenses: