nimbu-api 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2287c5c016c3257dd6f7751d3142c7d8258a854e
4
- data.tar.gz: c6c4be318b570741700b6dae07f69fb101ec7515
3
+ metadata.gz: a289593238198dc1e0293a1240c1e08e71e96724
4
+ data.tar.gz: d0b1a2bd1f661098cf5b963ac46477c8e23b9840
5
5
  SHA512:
6
- metadata.gz: cd5df8c86bafcb8947ecfcca896ff7db666edf666d89783b98355b77e4ed34bd982b1af260c69a59293a76b2bcd5d13b02c2b14a3b4c756f1c2ba1b846272cf1
7
- data.tar.gz: 8222b7e29f1bdb2e8dc9d0c94797c68c91c06014e67c92a0b18490d076f0474432e33165f04bc2f98c15db4b5744e9612da1876e2a8a906aae58996420903524
6
+ metadata.gz: 819375778ab5af0b4b2011bc89fe4c8b0db31e46e22d7d19a178798b55263c7129d27c8fec5dd2744c13881611cb8dfe6e50afbc25d238b864980d946425f8ec
7
+ data.tar.gz: c50214737928a355554638f1dcb767c991ad232145dd27ad100f5d009244312c3c83e43e8c8434dc9128d743a82d3a31718858712087bf4dab8042ea12a61c16
@@ -18,6 +18,7 @@ module Nimbu
18
18
  :password,
19
19
  :basic_auth,
20
20
  :auto_pagination,
21
+ :content_locale,
21
22
  :adapter
22
23
  ].freeze
23
24
 
@@ -63,6 +64,9 @@ module Nimbu
63
64
  # By default, don't traverse the page links
64
65
  DEFAULT_AUTO_PAGINATION = false
65
66
 
67
+ # By default, don't set a content_locale
68
+ DEFAULT_CONTENT_LOCALE = nil
69
+
66
70
  # Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
67
71
  DEFAULT_ADAPTER = :net_http
68
72
 
@@ -105,6 +109,7 @@ module Nimbu
105
109
  self.password = DEFAULT_PASSWORD
106
110
  self.basic_auth = DEFAULT_BASIC_AUTH
107
111
  self.auto_pagination = DEFAULT_AUTO_PAGINATION
112
+ self.content_locale = DEFAULT_CONTENT_LOCALE
108
113
  self.adapter = DEFAULT_ADAPTER
109
114
  self.subdomain = DEFAULT_SUBDOMAIN
110
115
  self
@@ -35,6 +35,7 @@ module Nimbu
35
35
  builder.use Nimbu::Request::BasicAuth, authentication if basic_authed?
36
36
  builder.use Nimbu::Request::UserAgent
37
37
  builder.use Nimbu::Request::SiteHeader, subdomain
38
+ builder.use Nimbu::Request::ContentLocale, content_locale
38
39
 
39
40
  builder.use Faraday::Response::Logger if ENV['DEBUG']
40
41
  builder.use Nimbu::Response::RaiseError
@@ -7,6 +7,7 @@ require 'nimbu-api/request/validations'
7
7
  require 'nimbu-api/request/arguments'
8
8
  require 'nimbu-api/request/user_agent'
9
9
  require 'nimbu-api/request/site_header'
10
+ require 'nimbu-api/request/content_locale'
10
11
 
11
12
  module Nimbu
12
13
 
@@ -13,6 +13,7 @@ module Nimbu
13
13
  include Validations
14
14
 
15
15
  AUTO_PAGINATION = 'auto_pagination'.freeze
16
+ CONTENT_LOCALE = 'content_locale'.freeze
16
17
 
17
18
  # Parameters passed to request
18
19
  attr_reader :params
@@ -61,6 +62,7 @@ module Nimbu
61
62
  @params = options
62
63
  @remaining = extract_remaining(args)
63
64
  extract_pagination(options)
65
+ extract_content_locale(options)
64
66
  yield_or_eval(&block)
65
67
  self
66
68
  end
@@ -115,6 +117,13 @@ module Nimbu
115
117
  end
116
118
  end
117
119
 
120
+ # Find content_locale parameter in options hash
121
+ def extract_content_locale(options)
122
+ if (value = options.delete(CONTENT_LOCALE))
123
+ api.content_locale = value
124
+ end
125
+ end
126
+
118
127
  # Remove required arguments from parameters and
119
128
  # validate their presence(if not nil or empty string).
120
129
  #
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'faraday'
4
+
5
+ module Nimbu
6
+ module Request
7
+ class ContentLocale < Faraday::Middleware
8
+ include Nimbu::Utils::Url
9
+
10
+ CONTENT_LOCALE = 'content_locale'.freeze
11
+
12
+ def call(env)
13
+ if @content_locale
14
+ params = { CONTENT_LOCALE => @content_locale }.update query_params(env[:url])
15
+ env[:url].query = build_query params
16
+ end
17
+
18
+ @app.call env
19
+ end
20
+
21
+ def initialize(app, *args)
22
+ super app
23
+ @app = app
24
+ @content_locale = args.shift
25
+ end
26
+
27
+ def query_params(url)
28
+ if url.query.nil? or url.query.empty?
29
+ {}
30
+ else
31
+ parse_query url.query
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -17,7 +17,8 @@ module Nimbu
17
17
  VALID_API_KEYS = [
18
18
  'page',
19
19
  'per_page',
20
- 'auto_pagination'
20
+ 'auto_pagination',
21
+ 'content_locale'
21
22
  ]
22
23
 
23
24
  end # Validation
@@ -1,5 +1,5 @@
1
1
  module Nimbu
2
2
  module API
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nimbu-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Dedene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2017-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -223,6 +223,7 @@ files:
223
223
  - lib/nimbu-api/request.rb
224
224
  - lib/nimbu-api/request/arguments.rb
225
225
  - lib/nimbu-api/request/basic_auth.rb
226
+ - lib/nimbu-api/request/content_locale.rb
226
227
  - lib/nimbu-api/request/json.rb
227
228
  - lib/nimbu-api/request/normalizer.rb
228
229
  - lib/nimbu-api/request/oauth2.rb
@@ -271,9 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
272
  version: '0'
272
273
  requirements: []
273
274
  rubyforge_project:
274
- rubygems_version: 2.2.0
275
+ rubygems_version: 2.4.5
275
276
  signing_key:
276
277
  specification_version: 4
277
278
  summary: Ruby bindings for the Nimbu API
278
279
  test_files: []
279
- has_rdoc: