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 +4 -4
- data/README.md +62 -5
- data/lib/barge.rb +1 -0
- data/lib/barge/resource/action.rb +2 -2
- data/lib/barge/resource/base.rb +4 -8
- data/lib/barge/resource/domain.rb +4 -4
- data/lib/barge/resource/droplet.rb +2 -2
- data/lib/barge/resource/image.rb +2 -2
- data/lib/barge/response.rb +38 -0
- data/lib/barge/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a580428f182b00e938e6b137ca19d27f875be4ad
|
4
|
+
data.tar.gz: 6fd36010dac884e132d4d137de028a140a5c2091
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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]
|
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
|
|
data/lib/barge.rb
CHANGED
data/lib/barge/resource/base.rb
CHANGED
@@ -3,7 +3,7 @@ module Barge
|
|
3
3
|
module Base
|
4
4
|
attr_reader :faraday
|
5
5
|
|
6
|
-
PER_PAGE =
|
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,
|
21
|
-
options = { per_page: PER_PAGE } if verb == :get
|
22
|
-
|
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)
|
data/lib/barge/resource/image.rb
CHANGED
@@ -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
|
data/lib/barge/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|
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:
|