nimbu-api 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -0
  3. data/README.md +25 -17
  4. data/lib/nimbu-api/client.rb +47 -28
  5. data/lib/nimbu-api/connection.rb +29 -31
  6. data/lib/nimbu-api/endpoint.rb +43 -44
  7. data/lib/nimbu-api/endpoints/activities.rb +3 -4
  8. data/lib/nimbu-api/endpoints/authorizations.rb +16 -23
  9. data/lib/nimbu-api/endpoints/blogs/articles.rb +60 -0
  10. data/lib/nimbu-api/endpoints/blogs.rb +48 -0
  11. data/lib/nimbu-api/endpoints/channels/entries.rb +19 -20
  12. data/lib/nimbu-api/endpoints/channels.rb +11 -13
  13. data/lib/nimbu-api/endpoints/collections.rb +10 -10
  14. data/lib/nimbu-api/endpoints/coupons.rb +10 -10
  15. data/lib/nimbu-api/endpoints/customers.rb +14 -14
  16. data/lib/nimbu-api/endpoints/devices.rb +11 -11
  17. data/lib/nimbu-api/endpoints/functions.rb +3 -4
  18. data/lib/nimbu-api/endpoints/jobs.rb +3 -4
  19. data/lib/nimbu-api/endpoints/login.rb +4 -7
  20. data/lib/nimbu-api/endpoints/menus.rb +48 -0
  21. data/lib/nimbu-api/endpoints/orders.rb +6 -6
  22. data/lib/nimbu-api/endpoints/pages.rb +50 -0
  23. data/lib/nimbu-api/endpoints/products.rb +16 -16
  24. data/lib/nimbu-api/endpoints/redirects.rb +50 -0
  25. data/lib/nimbu-api/endpoints/roles.rb +10 -10
  26. data/lib/nimbu-api/endpoints/simulator.rb +3 -4
  27. data/lib/nimbu-api/endpoints/sites.rb +7 -9
  28. data/lib/nimbu-api/endpoints/themes/assets.rb +6 -8
  29. data/lib/nimbu-api/endpoints/themes/layouts.rb +7 -8
  30. data/lib/nimbu-api/endpoints/themes/snippets.rb +6 -8
  31. data/lib/nimbu-api/endpoints/themes/templates.rb +6 -8
  32. data/lib/nimbu-api/endpoints/themes.rb +14 -16
  33. data/lib/nimbu-api/endpoints/translations.rb +10 -10
  34. data/lib/nimbu-api/endpoints/uploads.rb +50 -0
  35. data/lib/nimbu-api/endpoints/users.rb +3 -4
  36. data/lib/nimbu-api/endpoints/videos.rb +6 -8
  37. data/lib/nimbu-api/endpoints/webhooks.rb +8 -8
  38. data/lib/nimbu-api/file.rb +13 -0
  39. data/lib/nimbu-api/version.rb +3 -1
  40. data/lib/nimbu-api.rb +45 -37
  41. data/nimbu-api.gemspec +25 -16
  42. metadata +81 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff45e3502100e6c7b27a5e133fd72404d18ea95094de0cc2603a97218f53baf9
4
- data.tar.gz: 828d0760339cd0077cbffff8a1a2454f80e518b0723a511942e3d4bd2f37aeb6
3
+ metadata.gz: e544e690c2986aa829287ab083b3caf6a89b2f24f9caeb9f4e748431f341b937
4
+ data.tar.gz: e85e1b223f23f61afd5809e484b3e7e2f4c7563783e55eff2c458c80802365ee
5
5
  SHA512:
6
- metadata.gz: dbec9008321be132f0ad9ed0a2e873154c71dc8b1bd9d87d4b1a46734d9ca511eaf6f3384dc06cf63b5534448cd95a2557197cbf70174727b38da016bb344e6e
7
- data.tar.gz: 8935d575d7e1bf6f416d990c3c3c16ecd10819ccc68bb9b5d20704a05f4438d0e78bc13226225c69343b88819ffea1a5777840065185762f97c9943b1677eaa4
6
+ metadata.gz: a42f47b2f1769df780d03ef826f91da50cf0310da8b61742fbd8d64b9ba4afe756bf7f0794274af285bf635f540906b6403e56ad15c5af83ef6a3ca002548355
7
+ data.tar.gz: a712940ff8ce221fc569651b6e82181d3bcc1f896ccb6a1f558b86b1fe0e889796fdf2da067684ba5423f98ad6bdd95a6a00fec40d1e20960116c9581197558d
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ require: rubocop-performance
5
+
6
+ Performance:
7
+ Enabled: true
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 2.5
11
+ NewCops: disable
12
+ Exclude:
13
+ - 'vendor/**/*'
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 oauth_token: 'token'
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 enterprise endpoint and website like
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 your login and password:
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 login:'peter', password:'...'
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 basic_auth: 'login:password'
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 given channel,
73
- you can lookup the nimbu api spec and parse the request as in `nimbu.channels(channel_id: 'mychannel').entries.create`
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 attributes like method calls i.e.
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 :oauth_token => '...', :subdomain => '...', :channel_id => '...'
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 instance creation:
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 :oauth_token => '...', :subdomain => '...', :channel_id => '...'
90
- channel.entries.list state: 'public'
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 matters and hence please consult the method documentation or Nimbu specification. For instance:
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 :oauth_token => '...', :subdomain => '...'
97
- channel.entries.list channel_id: '...', state: 'public'
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 :oauth_token => '...', :subdomain => '...'
111
+ channel = Nimbu::Channel.new(oauth_token: '...', subdomain: '...')
104
112
  channel.entries(channel_id: '...').list(state: 'public')
105
- ```
113
+ ```
@@ -1,62 +1,81 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
- require 'nimbu-api/builder'
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
20
+
21
+ def channels(options = {}, &block)
22
+ Nimbu::Builder.new("Channels", current_options.merge(options), &block)
23
+ end
7
24
 
8
- def oauth(options={}, &block)
9
- Nimbu::Builder.new('Authorizations', current_options.merge(options), &block)
25
+ def videos(options = {}, &block)
26
+ Nimbu::Builder.new("Videos", current_options.merge(options), &block)
10
27
  end
11
- alias :authorizations :oauth
12
28
 
13
- def sites(options={}, &block)
14
- Nimbu::Builder.new('Sites', current_options.merge(options), &block)
29
+ def simulator(options = {}, &block)
30
+ Nimbu::Builder.new("Simulator", current_options.merge(options), &block)
15
31
  end
16
32
 
17
- def themes(options={}, &block)
18
- Nimbu::Builder.new('Themes', current_options.merge(options), &block)
33
+ def products(options = {}, &block)
34
+ Nimbu::Builder.new("Products", current_options.merge(options), &block)
19
35
  end
20
36
 
21
- def channels(options={}, &block)
22
- Nimbu::Builder.new('Channels', current_options.merge(options), &block)
37
+ def customers(options = {}, &block)
38
+ Nimbu::Builder.new("Customers", current_options.merge(options), &block)
23
39
  end
24
40
 
25
- def videos(options={}, &block)
26
- Nimbu::Builder.new('Videos', current_options.merge(options), &block)
41
+ def collections(options = {}, &block)
42
+ Nimbu::Builder.new("Collections", current_options.merge(options), &block)
27
43
  end
28
44
 
29
- def simulator(options={}, &block)
30
- Nimbu::Builder.new('Simulator', current_options.merge(options), &block)
45
+ def devices(options = {}, &block)
46
+ Nimbu::Builder.new("Devices", current_options.merge(options), &block)
31
47
  end
32
48
 
33
- def products(options={}, &block)
34
- Nimbu::Builder.new('Products', current_options.merge(options), &block)
49
+ def coupons(options = {}, &block)
50
+ Nimbu::Builder.new("Coupons", current_options.merge(options), &block)
35
51
  end
36
52
 
37
- def customers(options={}, &block)
38
- Nimbu::Builder.new('Customers', current_options.merge(options), &block)
53
+ def authenticate(options = {}, &block)
54
+ Nimbu::Builder.new("Login", current_options.merge(options), &block).response
39
55
  end
40
56
 
41
- def collections(options={}, &block)
42
- Nimbu::Builder.new('Collections', current_options.merge(options), &block)
57
+ def users(options = {}, &block)
58
+ Nimbu::Builder.new("Users", current_options.merge(options), &block)
43
59
  end
44
60
 
45
- def devices(options={}, &block)
46
- Nimbu::Builder.new('Devices', current_options.merge(options), &block)
61
+ def pages(options = {}, &block)
62
+ Nimbu::Builder.new("Pages", current_options.merge(options), &block)
47
63
  end
48
64
 
49
- def coupons(options={}, &block)
50
- Nimbu::Builder.new('Coupons', current_options.merge(options), &block)
65
+ def menus(options = {}, &block)
66
+ Nimbu::Builder.new("Menus", current_options.merge(options), &block)
51
67
  end
52
68
 
53
- def authenticate(options={}, &block)
54
- Nimbu::Builder.new('Login', current_options.merge(options), &block).response
69
+ def blogs(options = {}, &block)
70
+ Nimbu::Builder.new("Blogs", current_options.merge(options), &block)
55
71
  end
56
72
 
57
- def users(options={}, &block)
58
- Nimbu::Builder.new('Users', current_options.merge(options), &block)
73
+ def redirects(options = {}, &block)
74
+ Nimbu::Builder.new("Redirects", current_options.merge(options), &block)
59
75
  end
60
76
 
77
+ def uploads(options = {}, &block)
78
+ Nimbu::Builder.new("Uploads", current_options.merge(options), &block)
79
+ end
61
80
  end # Client
62
81
  end # Nimbu
@@ -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
- :ssl => options.fetch(:ssl) { ssl },
19
- :url => options.fetch(:endpoint) { Nimbu.endpoint }
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
- Proc.new do |builder|
27
+ def default_middleware(options = {})
28
+ proc do |builder|
28
29
  unless options[:with_attachments]
29
- builder.use Nimbu::Request::Json
30
+ builder.use(Nimbu::Request::Json)
30
31
  end
31
- builder.use Faraday::Request::Multipart
32
- builder.use Faraday::Request::UrlEncoded
33
- builder.use Nimbu::Request::OAuth2, oauth_token if oauth_token?
34
- builder.use Nimbu::Request::BasicAuth, authentication if basic_authed?
35
- builder.use Nimbu::Request::UserAgent
36
- builder.use Nimbu::Request::SiteHeader, subdomain
37
- builder.use Nimbu::Request::ContentLocale, content_locale
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 Faraday::Response::Logger if ENV['DEBUG']
40
- builder.use Nimbu::Response::RaiseError
40
+ builder.use(Faraday::Response::Logger) if ENV["DEBUG"]
41
+ builder.use(Nimbu::Response::RaiseError)
41
42
  unless options[:raw]
42
- builder.use Nimbu::Response::Mashify
43
- builder.use Nimbu::Response::Json
43
+ builder.use(Nimbu::Response::Mashify)
44
+ builder.use(Nimbu::Response::Json)
44
45
  end
45
- builder.adapter 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 ||= begin
66
- if block_given?
67
- Faraday::RackBuilder.new(&block)
68
- else
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? k }
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['DEBUG']
78
+ puts "OPTIONS:#{conn_options.inspect}" if ENV["DEBUG"]
80
79
 
81
- Faraday.new(conn_options.merge(:builder => stack(options)))
80
+ Faraday.new(conn_options.merge(builder: stack(options)))
82
81
  end
83
-
84
82
  end # Connection
85
83
  end # Nimbu
@@ -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 *Configuration.keys
12
- attr_accessor *Request::Validations::VALID_API_KEYS
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 <<-RUBY_EVAL, __FILE__, __LINE__ + 1
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) - ['actions']).sort.each do |method|
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
- if mod.to_s =~ /#{klass}/
36
- puts "| \\ #{mod.to_s}"
37
- mod.instance_methods(false).each do |met|
38
- puts "| |--> #{met}"
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
- args = "()"
49
+ args = if _method.arity == 0
50
+ "()"
51
51
  elsif _method.arity > 0
52
- args = "(few)"
52
+ "(few)"
53
53
  else
54
- args = "(else)"
54
+ "(else)"
55
55
  end
56
56
  args
57
57
  end
58
58
 
59
59
  # Callback to update current configuration options
60
- class_eval do
61
- Configuration.keys.each do |key|
62
- define_method "#{key}=" do |arg|
63
- self.instance_variable_set("@#{key}", arg)
64
- self.current_options.merge!({:"#{key}" => arg})
65
- end
66
- end
67
- end
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) : self.instance_eval(&block)
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
- self.set(k,v,true)
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(':', 2)
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
- return !!self.send($1.to_s)
112
+ !!send(Regexp.last_match(1).to_s)
113
113
  when /^clear_(.*)$/
114
- self.send("#{$1.to_s}=", nil)
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 args
137
+ set(args)
138
138
  else
139
- ::Kernel.raise ArgumentError, 'This api does not support passed in arguments'
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, 'value not set' if block and !not_set
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 option
149
+ set_options(option)
150
150
  return self
151
151
  end
152
152
 
153
- if respond_to?("#{option}=") and not ignore_setter
153
+ if respond_to?("#{option}=") and !ignore_setter
154
154
  return __send__("#{option}=", value)
155
155
  end
156
156
 
157
- define_accessors option, value
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, 'cannot iterate over value'
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| set option, val, true }
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, :required => [:activity_id])
8
+ arguments(args, required: [:activity_id])
9
9
 
10
10
  get_request("/activities/#{activity_id}", arguments.params)
11
11
  end
12
- alias :find :get
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
- VALID_AUTH_PARAM_NAMES = %w[
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 { |el| yield el }
23
+ response.each(&block)
31
24
  end
32
- alias :all :list
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, :required => [:authorization_id])
35
+ arguments(args, required: [:authorization_id])
43
36
 
44
37
  get_request("/authorizations/#{authorization_id}", arguments.params)
45
38
  end
46
- alias :find :get
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 VALID_AUTH_PARAM_NAMES
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, :required => [:authorization_id]) do
85
- sift VALID_AUTH_PARAM_NAMES
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
- alias :edit :update
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, :required => [:authorization_id])
92
+ arguments(args, required: [:authorization_id])
100
93
 
101
94
  delete_request("/authorizations/#{authorization_id}", arguments.params)
102
95
  end
103
- alias :remove :delete
96
+ alias_method :remove, :delete
104
97
 
105
98
  private
106
99
 
107
100
  def require_authentication
108
- raise ArgumentError, 'You can only access authentication tokens through Basic Authentication' unless authenticated?
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