nimbu-api 0.4.2 → 0.5.0
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 +4 -4
- data/.rubocop.yml +13 -0
- data/README.md +25 -17
- data/lib/nimbu-api/client.rb +49 -26
- data/lib/nimbu-api/connection.rb +29 -31
- data/lib/nimbu-api/endpoint.rb +43 -44
- data/lib/nimbu-api/endpoints/activities.rb +3 -4
- data/lib/nimbu-api/endpoints/authorizations.rb +16 -23
- data/lib/nimbu-api/endpoints/blogs/articles.rb +60 -0
- data/lib/nimbu-api/endpoints/blogs.rb +48 -0
- data/lib/nimbu-api/endpoints/channels/entries.rb +19 -20
- data/lib/nimbu-api/endpoints/channels.rb +11 -13
- data/lib/nimbu-api/endpoints/collections.rb +10 -10
- data/lib/nimbu-api/endpoints/coupons.rb +10 -10
- data/lib/nimbu-api/endpoints/customers.rb +14 -14
- data/lib/nimbu-api/endpoints/devices.rb +11 -11
- data/lib/nimbu-api/endpoints/functions.rb +3 -4
- data/lib/nimbu-api/endpoints/jobs.rb +3 -4
- data/lib/nimbu-api/endpoints/login.rb +4 -7
- data/lib/nimbu-api/endpoints/menus.rb +48 -0
- data/lib/nimbu-api/endpoints/orders.rb +6 -6
- data/lib/nimbu-api/endpoints/pages.rb +50 -0
- data/lib/nimbu-api/endpoints/products.rb +16 -16
- data/lib/nimbu-api/endpoints/redirects.rb +50 -0
- data/lib/nimbu-api/endpoints/roles.rb +10 -10
- data/lib/nimbu-api/endpoints/simulator.rb +3 -4
- data/lib/nimbu-api/endpoints/sites.rb +7 -9
- data/lib/nimbu-api/endpoints/themes/assets.rb +9 -10
- data/lib/nimbu-api/endpoints/themes/layouts.rb +7 -8
- data/lib/nimbu-api/endpoints/themes/snippets.rb +6 -8
- data/lib/nimbu-api/endpoints/themes/templates.rb +6 -8
- data/lib/nimbu-api/endpoints/themes.rb +14 -16
- data/lib/nimbu-api/endpoints/translations.rb +10 -10
- data/lib/nimbu-api/endpoints/uploads.rb +50 -0
- data/lib/nimbu-api/endpoints/users.rb +21 -0
- data/lib/nimbu-api/endpoints/videos.rb +6 -8
- data/lib/nimbu-api/endpoints/webhooks.rb +8 -8
- data/lib/nimbu-api/file.rb +13 -0
- data/lib/nimbu-api/request.rb +1 -1
- data/lib/nimbu-api/version.rb +3 -1
- data/lib/nimbu-api.rb +46 -37
- data/nimbu-api.gemspec +25 -16
- metadata +82 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e544e690c2986aa829287ab083b3caf6a89b2f24f9caeb9f4e748431f341b937
|
4
|
+
data.tar.gz: e85e1b223f23f61afd5809e484b3e7e2f4c7563783e55eff2c458c80802365ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a42f47b2f1769df780d03ef826f91da50cf0310da8b61742fbd8d64b9ba4afe756bf7f0794274af285bf635f540906b6403e56ad15c5af83ef6a3ca002548355
|
7
|
+
data.tar.gz: a712940ff8ce221fc569651b6e82181d3bcc1f896ccb6a1f558b86b1fe0e889796fdf2da067684ba5423f98ad6bdd95a6a00fec40d1e20960116c9581197558d
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -27,6 +27,7 @@ nimbu = Nimbu.new
|
|
27
27
|
```
|
28
28
|
|
29
29
|
You can supply following configuration parameters, such as
|
30
|
+
|
30
31
|
```
|
31
32
|
auto_pagination # by default false, set to true traverses requests page links
|
32
33
|
oauth_token # oauth authorization token
|
@@ -40,13 +41,15 @@ You can supply following configuration parameters, such as
|
|
40
41
|
per_page # number of items per page, max 100
|
41
42
|
user_agent # custom user agent name, by default 'Nimbu Ruby Client'
|
42
43
|
```
|
44
|
+
|
43
45
|
which are used throughout the API. These can be passed directly as hash options:
|
44
46
|
|
45
47
|
```ruby
|
46
|
-
nimbu = Nimbu.new
|
48
|
+
nimbu = Nimbu.new(oauth_token: 'token')
|
47
49
|
```
|
48
50
|
|
49
|
-
Alternatively, you can configure the Nimbu settings by passing a block, for instance, with custom
|
51
|
+
Alternatively, you can configure the Nimbu settings by passing a block, for instance, with custom
|
52
|
+
enterprise endpoint and website like
|
50
53
|
|
51
54
|
```ruby
|
52
55
|
nimbu = Nimbu.new do |config|
|
@@ -57,25 +60,28 @@ nimbu = Nimbu.new do |config|
|
|
57
60
|
end
|
58
61
|
```
|
59
62
|
|
60
|
-
You can authenticate either using OAuth authentication or through basic authentication by passing
|
63
|
+
You can authenticate either using OAuth authentication or through basic authentication by passing
|
64
|
+
your login and password:
|
61
65
|
|
62
66
|
```ruby
|
63
|
-
nimbu = Nimbu.new
|
67
|
+
nimbu = Nimbu.new(login:'peter', password:'...')
|
64
68
|
```
|
65
69
|
|
66
70
|
or use following convenience method:
|
67
71
|
|
68
72
|
```ruby
|
69
|
-
nimbu = Nimbu.new
|
73
|
+
nimbu = Nimbu.new(basic_auth: 'login:password')
|
70
74
|
```
|
71
75
|
|
72
|
-
This gem follows the Nimbu API hierarchy. This means, i.e. if you want to create a new entry for a
|
73
|
-
you can lookup the nimbu api spec and parse the request as in
|
76
|
+
This gem follows the Nimbu API hierarchy. This means, i.e. if you want to create a new entry for a
|
77
|
+
given channel, you can lookup the nimbu api spec and parse the request as in
|
78
|
+
`nimbu.channels(channel_id: 'mychannel').entries.create`
|
74
79
|
|
75
|
-
The response is always of type [Hashie::Mash] and allows to traverse all the json response
|
80
|
+
The response is always of type [Hashie::Mash] and allows to traverse all the json response
|
81
|
+
attributes like method calls i.e.
|
76
82
|
|
77
83
|
```ruby
|
78
|
-
entries = Nimbu::Channel::Entries.new
|
84
|
+
entries = Nimbu::Channel::Entries.new(oauth_token: '...', subdomain:'...', channel_id:'...')
|
79
85
|
entries.all do |entry|
|
80
86
|
puts entry.title
|
81
87
|
end
|
@@ -83,23 +89,25 @@ end
|
|
83
89
|
|
84
90
|
## Arguments & Parameters
|
85
91
|
|
86
|
-
The library allows for flexible arguments parsing. This means arguments can be passed during
|
92
|
+
The library allows for flexible arguments parsing. This means arguments can be passed during
|
93
|
+
instance creation:
|
87
94
|
|
88
95
|
```ruby
|
89
|
-
channel = Nimbu::Channel.new
|
90
|
-
channel.entries.list
|
96
|
+
channel = Nimbu::Channel.new(oauth_token:'...', subdomain:'...', channel_id:'...')
|
97
|
+
channel.entries.list(state: 'public')
|
91
98
|
```
|
92
99
|
|
93
|
-
Further, arguments can be passed directly inside method called but then the order of parameters
|
100
|
+
Further, arguments can be passed directly inside method called but then the order of parameters
|
101
|
+
matters and hence please consult the method documentation or Nimbu specification. For instance:
|
94
102
|
|
95
103
|
```ruby
|
96
|
-
channel = Nimbu::Channel.new
|
97
|
-
channel.entries.list
|
104
|
+
channel = Nimbu::Channel.new(oauth_token: '...', subdomain: '...')
|
105
|
+
channel.entries.list(channel_id: '...', state: 'public')
|
98
106
|
```
|
99
107
|
|
100
108
|
Similarly, the arguments for the request can be passed inside the current scope such as:
|
101
109
|
|
102
110
|
```ruby
|
103
|
-
channel = Nimbu::Channel.new
|
111
|
+
channel = Nimbu::Channel.new(oauth_token: '...', subdomain: '...')
|
104
112
|
channel.entries(channel_id: '...').list(state: 'public')
|
105
|
-
```
|
113
|
+
```
|
data/lib/nimbu-api/client.rb
CHANGED
@@ -1,58 +1,81 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
+
require "nimbu-api/builder"
|
4
5
|
|
5
6
|
module Nimbu
|
6
7
|
class Client < Endpoint
|
8
|
+
def oauth(options = {}, &block)
|
9
|
+
Nimbu::Builder.new("Authorizations", current_options.merge(options), &block)
|
10
|
+
end
|
11
|
+
alias_method :authorizations, :oauth
|
12
|
+
|
13
|
+
def sites(options = {}, &block)
|
14
|
+
Nimbu::Builder.new("Sites", current_options.merge(options), &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def themes(options = {}, &block)
|
18
|
+
Nimbu::Builder.new("Themes", current_options.merge(options), &block)
|
19
|
+
end
|
7
20
|
|
8
|
-
def
|
9
|
-
Nimbu::Builder.new(
|
21
|
+
def channels(options = {}, &block)
|
22
|
+
Nimbu::Builder.new("Channels", current_options.merge(options), &block)
|
10
23
|
end
|
11
|
-
alias :authorizations :oauth
|
12
24
|
|
13
|
-
def
|
14
|
-
Nimbu::Builder.new(
|
25
|
+
def videos(options = {}, &block)
|
26
|
+
Nimbu::Builder.new("Videos", current_options.merge(options), &block)
|
15
27
|
end
|
16
28
|
|
17
|
-
def
|
18
|
-
Nimbu::Builder.new(
|
29
|
+
def simulator(options = {}, &block)
|
30
|
+
Nimbu::Builder.new("Simulator", current_options.merge(options), &block)
|
19
31
|
end
|
20
32
|
|
21
|
-
def
|
22
|
-
Nimbu::Builder.new(
|
33
|
+
def products(options = {}, &block)
|
34
|
+
Nimbu::Builder.new("Products", current_options.merge(options), &block)
|
23
35
|
end
|
24
36
|
|
25
|
-
def
|
26
|
-
Nimbu::Builder.new(
|
37
|
+
def customers(options = {}, &block)
|
38
|
+
Nimbu::Builder.new("Customers", current_options.merge(options), &block)
|
27
39
|
end
|
28
40
|
|
29
|
-
def
|
30
|
-
Nimbu::Builder.new(
|
41
|
+
def collections(options = {}, &block)
|
42
|
+
Nimbu::Builder.new("Collections", current_options.merge(options), &block)
|
31
43
|
end
|
32
44
|
|
33
|
-
def
|
34
|
-
Nimbu::Builder.new(
|
45
|
+
def devices(options = {}, &block)
|
46
|
+
Nimbu::Builder.new("Devices", current_options.merge(options), &block)
|
35
47
|
end
|
36
48
|
|
37
|
-
def
|
38
|
-
Nimbu::Builder.new(
|
49
|
+
def coupons(options = {}, &block)
|
50
|
+
Nimbu::Builder.new("Coupons", current_options.merge(options), &block)
|
39
51
|
end
|
40
52
|
|
41
|
-
def
|
42
|
-
Nimbu::Builder.new(
|
53
|
+
def authenticate(options = {}, &block)
|
54
|
+
Nimbu::Builder.new("Login", current_options.merge(options), &block).response
|
43
55
|
end
|
44
56
|
|
45
|
-
def
|
46
|
-
Nimbu::Builder.new(
|
57
|
+
def users(options = {}, &block)
|
58
|
+
Nimbu::Builder.new("Users", current_options.merge(options), &block)
|
47
59
|
end
|
48
60
|
|
49
|
-
def
|
50
|
-
Nimbu::Builder.new(
|
61
|
+
def pages(options = {}, &block)
|
62
|
+
Nimbu::Builder.new("Pages", current_options.merge(options), &block)
|
51
63
|
end
|
52
64
|
|
53
|
-
def
|
54
|
-
Nimbu::Builder.new(
|
65
|
+
def menus(options = {}, &block)
|
66
|
+
Nimbu::Builder.new("Menus", current_options.merge(options), &block)
|
55
67
|
end
|
56
68
|
|
69
|
+
def blogs(options = {}, &block)
|
70
|
+
Nimbu::Builder.new("Blogs", current_options.merge(options), &block)
|
71
|
+
end
|
72
|
+
|
73
|
+
def redirects(options = {}, &block)
|
74
|
+
Nimbu::Builder.new("Redirects", current_options.merge(options), &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
def uploads(options = {}, &block)
|
78
|
+
Nimbu::Builder.new("Uploads", current_options.merge(options), &block)
|
79
|
+
end
|
57
80
|
end # Client
|
58
81
|
end # Nimbu
|
data/lib/nimbu-api/connection.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Nimbu
|
4
5
|
module Connection
|
@@ -10,39 +11,39 @@ module Nimbu
|
|
10
11
|
:url,
|
11
12
|
:params,
|
12
13
|
:request,
|
13
|
-
:ssl
|
14
|
+
:ssl,
|
14
15
|
].freeze
|
15
16
|
|
16
|
-
def default_options(options={})
|
17
|
+
def default_options(options = {})
|
17
18
|
{
|
18
|
-
:
|
19
|
-
:
|
19
|
+
ssl: options.fetch(:ssl) { ssl },
|
20
|
+
url: options.fetch(:endpoint) { Nimbu.endpoint },
|
20
21
|
}.merge(options)
|
21
22
|
end
|
22
23
|
|
23
24
|
# Default middleware stack that uses default adapter as specified at
|
24
25
|
# configuration stage.
|
25
26
|
#
|
26
|
-
def default_middleware(options={})
|
27
|
-
|
27
|
+
def default_middleware(options = {})
|
28
|
+
proc do |builder|
|
28
29
|
unless options[:with_attachments]
|
29
|
-
builder.use
|
30
|
+
builder.use(Nimbu::Request::Json)
|
30
31
|
end
|
31
|
-
builder.use
|
32
|
-
builder.use
|
33
|
-
builder.use
|
34
|
-
builder.use
|
35
|
-
builder.use
|
36
|
-
builder.use
|
37
|
-
builder.use
|
32
|
+
builder.use(Faraday::Request::Multipart)
|
33
|
+
builder.use(Faraday::Request::UrlEncoded)
|
34
|
+
builder.use(Nimbu::Request::OAuth2, oauth_token) if oauth_token?
|
35
|
+
builder.use(Nimbu::Request::BasicAuth, authentication) if basic_authed?
|
36
|
+
builder.use(Nimbu::Request::UserAgent)
|
37
|
+
builder.use(Nimbu::Request::SiteHeader, subdomain)
|
38
|
+
builder.use(Nimbu::Request::ContentLocale, content_locale)
|
38
39
|
|
39
|
-
builder.use
|
40
|
-
builder.use
|
40
|
+
builder.use(Faraday::Response::Logger) if ENV["DEBUG"]
|
41
|
+
builder.use(Nimbu::Response::RaiseError)
|
41
42
|
unless options[:raw]
|
42
|
-
builder.use
|
43
|
-
builder.use
|
43
|
+
builder.use(Nimbu::Response::Mashify)
|
44
|
+
builder.use(Nimbu::Response::Json)
|
44
45
|
end
|
45
|
-
builder.adapter
|
46
|
+
builder.adapter(adapter)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -61,25 +62,22 @@ module Nimbu
|
|
61
62
|
# Exposes middleware builder to facilitate custom stacks and easy
|
62
63
|
# addition of new extensions such as cache adapter.
|
63
64
|
#
|
64
|
-
def stack(options={}, &block)
|
65
|
-
@stack ||=
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Faraday::RackBuilder.new(&default_middleware(options))
|
70
|
-
end
|
65
|
+
def stack(options = {}, &block)
|
66
|
+
@stack ||= if block_given?
|
67
|
+
Faraday::RackBuilder.new(&block)
|
68
|
+
else
|
69
|
+
Faraday::RackBuilder.new(&default_middleware(options))
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
74
73
|
# Returns a Fraday::Connection object
|
75
74
|
#
|
76
|
-
def connection(options={})
|
77
|
-
conn_options = default_options(options).keep_if {|k,_| ALLOWED_OPTIONS.include?
|
75
|
+
def connection(options = {})
|
76
|
+
conn_options = default_options(options).keep_if { |k, _| ALLOWED_OPTIONS.include?(k) }
|
78
77
|
clear_cache unless options.empty?
|
79
|
-
puts "OPTIONS:#{conn_options.inspect}" if ENV[
|
78
|
+
puts "OPTIONS:#{conn_options.inspect}" if ENV["DEBUG"]
|
80
79
|
|
81
|
-
Faraday.new(conn_options.merge(:
|
80
|
+
Faraday.new(conn_options.merge(builder: stack(options)))
|
82
81
|
end
|
83
|
-
|
84
82
|
end # Connection
|
85
83
|
end # Nimbu
|
data/lib/nimbu-api/endpoint.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Nimbu
|
4
5
|
# Core class for api interface operations
|
@@ -8,14 +9,14 @@ module Nimbu
|
|
8
9
|
include Connection
|
9
10
|
include Request
|
10
11
|
|
11
|
-
attr_reader
|
12
|
-
attr_accessor
|
12
|
+
attr_reader(*Configuration.keys)
|
13
|
+
attr_accessor(*Request::Validations::VALID_API_KEYS)
|
13
14
|
|
14
15
|
attr_accessor :current_options
|
15
16
|
|
16
17
|
# Returns all API public methods for a given class.
|
17
18
|
def self.inherited(klass)
|
18
|
-
klass.class_eval
|
19
|
+
klass.class_eval(<<-RUBY_EVAL, __FILE__, __LINE__ + 1)
|
19
20
|
def self.actions
|
20
21
|
self.new.api_methods_in(#{klass})
|
21
22
|
end
|
@@ -28,17 +29,16 @@ module Nimbu
|
|
28
29
|
|
29
30
|
def api_methods_in(klass)
|
30
31
|
puts "---"
|
31
|
-
(klass.send(:instance_methods, false) - [
|
32
|
+
(klass.send(:instance_methods, false) - ["actions"]).sort.each do |method|
|
32
33
|
puts "|--> #{method}"
|
33
34
|
end
|
34
35
|
klass.included_modules.each do |mod|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
puts "| /"
|
36
|
+
next unless /#{klass}/.match?(mod.to_s)
|
37
|
+
puts "| \\ #{mod}"
|
38
|
+
mod.instance_methods(false).each do |met|
|
39
|
+
puts "| |--> #{met}"
|
41
40
|
end
|
41
|
+
puts "| /"
|
42
42
|
end
|
43
43
|
puts "---"
|
44
44
|
nil
|
@@ -46,29 +46,29 @@ module Nimbu
|
|
46
46
|
|
47
47
|
def append_arguments(method)
|
48
48
|
_method = self.method(method)
|
49
|
-
if _method.arity == 0
|
50
|
-
|
49
|
+
args = if _method.arity == 0
|
50
|
+
"()"
|
51
51
|
elsif _method.arity > 0
|
52
|
-
|
52
|
+
"(few)"
|
53
53
|
else
|
54
|
-
|
54
|
+
"(else)"
|
55
55
|
end
|
56
56
|
args
|
57
57
|
end
|
58
58
|
|
59
59
|
# Callback to update current configuration options
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
class_eval do
|
61
|
+
Configuration.keys.each do |key|
|
62
|
+
define_method "#{key}=" do |arg|
|
63
|
+
instance_variable_set("@#{key}", arg)
|
64
|
+
current_options.merge!({ "#{key}": arg })
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
68
|
|
69
69
|
# Create new API
|
70
70
|
#
|
71
|
-
def initialize(options={}, &block)
|
71
|
+
def initialize(options = {}, &block)
|
72
72
|
setup(options)
|
73
73
|
client(options) if client_id? && client_secret?
|
74
74
|
yield_or_eval(&block) if block_given?
|
@@ -76,14 +76,14 @@ module Nimbu
|
|
76
76
|
|
77
77
|
def yield_or_eval(&block)
|
78
78
|
return unless block
|
79
|
-
block.arity > 0 ? yield(self) :
|
79
|
+
block.arity > 0 ? yield(self) : instance_eval(&block)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Configure options and process basic authorization
|
83
83
|
#
|
84
|
-
def setup(options={})
|
85
|
-
options.each do |k,v|
|
86
|
-
|
84
|
+
def setup(options = {})
|
85
|
+
options.each do |k, v|
|
86
|
+
set(k, v, true)
|
87
87
|
end
|
88
88
|
options = Nimbu.options.merge(options)
|
89
89
|
self.current_options = options
|
@@ -98,7 +98,7 @@ module Nimbu
|
|
98
98
|
def process_basic_auth(auth)
|
99
99
|
case auth
|
100
100
|
when String
|
101
|
-
self.login, self.password = auth.split(
|
101
|
+
self.login, self.password = auth.split(":", 2)
|
102
102
|
when Hash
|
103
103
|
self.login = auth[:login]
|
104
104
|
self.password = auth[:password]
|
@@ -109,9 +109,9 @@ module Nimbu
|
|
109
109
|
def method_missing(method, *args, &block) # :nodoc:
|
110
110
|
case method.to_s
|
111
111
|
when /^(.*)\?$/
|
112
|
-
|
112
|
+
!!send(Regexp.last_match(1).to_s)
|
113
113
|
when /^clear_(.*)$/
|
114
|
-
|
114
|
+
send("#{Regexp.last_match(1)}=", nil)
|
115
115
|
else
|
116
116
|
super
|
117
117
|
end
|
@@ -121,7 +121,7 @@ module Nimbu
|
|
121
121
|
#
|
122
122
|
# Returns Arguments instance.
|
123
123
|
#
|
124
|
-
def arguments(args=(not_set = true), options={}, &block)
|
124
|
+
def arguments(args = (not_set = true), options = {}, &block)
|
125
125
|
if not_set
|
126
126
|
@arguments
|
127
127
|
else
|
@@ -134,27 +134,27 @@ module Nimbu
|
|
134
134
|
def with(args)
|
135
135
|
case args
|
136
136
|
when Hash
|
137
|
-
set
|
137
|
+
set(args)
|
138
138
|
else
|
139
|
-
::Kernel.raise ArgumentError,
|
139
|
+
::Kernel.raise ArgumentError, "This api does not support passed in arguments"
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
143
|
# Set an option to a given value
|
144
|
-
def set(option, value=(not_set=true), ignore_setter=false, &block)
|
145
|
-
raise ArgumentError,
|
144
|
+
def set(option, value = (not_set = true), ignore_setter = false, &block)
|
145
|
+
raise ArgumentError, "value not set" if block and !not_set
|
146
146
|
return self if !not_set and value.nil?
|
147
147
|
|
148
148
|
if not_set
|
149
|
-
set_options
|
149
|
+
set_options(option)
|
150
150
|
return self
|
151
151
|
end
|
152
152
|
|
153
|
-
if respond_to?("#{option}=") and
|
153
|
+
if respond_to?("#{option}=") and !ignore_setter
|
154
154
|
return __send__("#{option}=", value)
|
155
155
|
end
|
156
156
|
|
157
|
-
define_accessors
|
157
|
+
define_accessors(option, value)
|
158
158
|
self
|
159
159
|
end
|
160
160
|
|
@@ -164,13 +164,13 @@ module Nimbu
|
|
164
164
|
#
|
165
165
|
def set_options(options)
|
166
166
|
unless options.respond_to?(:each)
|
167
|
-
raise ArgumentError,
|
167
|
+
raise ArgumentError, "cannot iterate over value"
|
168
168
|
end
|
169
169
|
options.each { |key, value| set(key, value) }
|
170
170
|
end
|
171
171
|
|
172
172
|
def define_accessors(option, value)
|
173
|
-
setter = proc { |val|
|
173
|
+
setter = proc { |val| set(option, val, true) }
|
174
174
|
getter = proc { value }
|
175
175
|
|
176
176
|
define_singleton_method("#{option}=", setter) if setter
|
@@ -179,7 +179,7 @@ module Nimbu
|
|
179
179
|
|
180
180
|
# Dynamically define a method for setting request option
|
181
181
|
#
|
182
|
-
def define_singleton_method(method_name, content=Proc.new)
|
182
|
+
def define_singleton_method(method_name, content = Proc.new)
|
183
183
|
(class << self; self; end).class_eval do
|
184
184
|
undef_method(method_name) if method_defined?(method_name)
|
185
185
|
if String === content
|
@@ -191,9 +191,8 @@ module Nimbu
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def _merge_mime_type(resource, params) # :nodoc:
|
194
|
-
# params['resource'] = resource
|
195
|
-
# params['mime_type'] = params['mime_type'] || :raw
|
194
|
+
# params['resource'] = resource
|
195
|
+
# params['mime_type'] = params['mime_type'] || :raw
|
196
196
|
end
|
197
|
-
|
198
197
|
end # Endpoint
|
199
198
|
end # Nimbu
|
@@ -1,16 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Nimbu
|
4
5
|
module Endpoints
|
5
6
|
class Activities < Endpoint
|
6
|
-
|
7
7
|
def get(*args)
|
8
|
-
arguments(args, :
|
8
|
+
arguments(args, required: [:activity_id])
|
9
9
|
|
10
10
|
get_request("/activities/#{activity_id}", arguments.params)
|
11
11
|
end
|
12
|
-
|
13
|
-
|
12
|
+
alias_method :find, :get
|
14
13
|
end # Authorizations
|
15
14
|
end # Endpoints
|
16
15
|
end # Nimbu
|
@@ -1,18 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Nimbu
|
4
5
|
module Endpoints
|
5
6
|
class Authorizations < Endpoint
|
6
|
-
|
7
|
-
|
8
|
-
scopes
|
9
|
-
add_scopes
|
10
|
-
remove_scopes
|
11
|
-
note
|
12
|
-
note_url
|
13
|
-
client_id
|
14
|
-
client_secret
|
15
|
-
].freeze
|
7
|
+
VALID_AUTH_PARAM_NAMES = ["scopes", "add_scopes", "remove_scopes", "note", "note_url", "client_id",
|
8
|
+
"client_secret",].freeze
|
16
9
|
|
17
10
|
# List authorizations
|
18
11
|
#
|
@@ -21,15 +14,15 @@ module Nimbu
|
|
21
14
|
# nimbu.oauth.list
|
22
15
|
# nimbu.oauth.list { |auth| ... }
|
23
16
|
#
|
24
|
-
def list(*args)
|
17
|
+
def list(*args, &block)
|
25
18
|
require_authentication
|
26
19
|
arguments(args)
|
27
20
|
|
28
21
|
response = get_request("/authorizations", arguments.params)
|
29
22
|
return response unless block_given?
|
30
|
-
response.each
|
23
|
+
response.each(&block)
|
31
24
|
end
|
32
|
-
|
25
|
+
alias_method :all, :list
|
33
26
|
|
34
27
|
# Get a single authorization
|
35
28
|
#
|
@@ -39,11 +32,11 @@ module Nimbu
|
|
39
32
|
#
|
40
33
|
def get(*args)
|
41
34
|
require_authentication
|
42
|
-
arguments(args, :
|
35
|
+
arguments(args, required: [:authorization_id])
|
43
36
|
|
44
37
|
get_request("/authorizations/#{authorization_id}", arguments.params)
|
45
38
|
end
|
46
|
-
|
39
|
+
alias_method :find, :get
|
47
40
|
|
48
41
|
# Create a new authorization
|
49
42
|
#
|
@@ -60,7 +53,7 @@ module Nimbu
|
|
60
53
|
def create(*args)
|
61
54
|
require_authentication
|
62
55
|
arguments(args) do
|
63
|
-
sift
|
56
|
+
sift(VALID_AUTH_PARAM_NAMES)
|
64
57
|
end
|
65
58
|
|
66
59
|
post_request("/authorizations", arguments.params)
|
@@ -81,13 +74,13 @@ module Nimbu
|
|
81
74
|
#
|
82
75
|
def update(*args)
|
83
76
|
require_authentication
|
84
|
-
arguments(args, :
|
85
|
-
sift
|
77
|
+
arguments(args, required: [:authorization_id]) do
|
78
|
+
sift(VALID_AUTH_PARAM_NAMES)
|
86
79
|
end
|
87
80
|
|
88
81
|
patch_request("/authorizations/#{authorization_id}", arguments.params)
|
89
82
|
end
|
90
|
-
|
83
|
+
alias_method :edit, :update
|
91
84
|
|
92
85
|
# Delete an authorization
|
93
86
|
#
|
@@ -96,18 +89,18 @@ module Nimbu
|
|
96
89
|
#
|
97
90
|
def delete(*args)
|
98
91
|
require_authentication
|
99
|
-
arguments(args, :
|
92
|
+
arguments(args, required: [:authorization_id])
|
100
93
|
|
101
94
|
delete_request("/authorizations/#{authorization_id}", arguments.params)
|
102
95
|
end
|
103
|
-
|
96
|
+
alias_method :remove, :delete
|
104
97
|
|
105
98
|
private
|
106
99
|
|
107
100
|
def require_authentication
|
108
|
-
raise ArgumentError,
|
101
|
+
raise ArgumentError,
|
102
|
+
"You can only access authentication tokens through Basic Authentication" unless authenticated?
|
109
103
|
end
|
110
|
-
|
111
104
|
end # Authorizations
|
112
105
|
end # Endpoints
|
113
106
|
end # Nimbu
|