reamaze_api 0.1.0 → 0.2.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: 8e117f4f567c26ad33a009c651600dacefdeaaa2
4
- data.tar.gz: b617e08ac63b8c0792f64da222a6c0d422c2714c
3
+ metadata.gz: f6ec9222307b2003945f7caa24a03c0488607dfd
4
+ data.tar.gz: ce976a2b44f32b5f0ab0847f56aa3c278c9f92f5
5
5
  SHA512:
6
- metadata.gz: 029895529560b1eb8e71e42120f517ca85359ab7e0d2476f62d80a8ae8f5f5e5301773947632f4434e592e741739bf21c0de337b7a84860baf46a7ffa433226f
7
- data.tar.gz: aafe067d2ea6a1e0537c5943a204b2fd216305ab13e53c994bfbe5bdacf69afbb6a3727da2bf48c8a010d7ca482d382667b84a297757d0beff379ed5dd4d33c3
6
+ metadata.gz: 6fcfa3aceaa6de884c933c0662b7d5f71587435fc60b1dd3bfd601cb2b93e5bb4da5cdfbef29d34ea3d127a02f3fe08fc45c83ec62c3c284ea18c7d51f3cf70e
7
+ data.tar.gz: 46e113b6446bcf32858fb606849ef33b5b769c06c2e42f6ab655c0fa32db1b4cddd5325d4fd756003c7c8615239c4eebc69600578363b04b1112b21d3df24b65
data/README.md CHANGED
@@ -9,7 +9,7 @@ Ruby library for working with the [Reamaze API][].
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'reamaze_api'
12
+ gem "reamaze_api"
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -74,6 +74,23 @@ Net::HTTP. To configure a different HTTP adapter you can set
74
74
  Faraday.default_adapter = :httpclient
75
75
  ```
76
76
 
77
+ If you need more customization for Faraday, for example, to add additional
78
+ middleware or change request headers, you can call `ReamazeAPI.new` with a
79
+ block:
80
+
81
+ ```ruby
82
+ class MyCoolMiddleware < Faraday::Response::Middleware
83
+ end
84
+
85
+ Faraday::Response.register_middleware \
86
+ my_cool_middleware: MyCoolMiddleware
87
+
88
+ client = ReamazeAPI.new do |http|
89
+ http.response :my_cool_middleware
90
+ http.headers["User-Agent"] = "My Reamaze Client"
91
+ end
92
+ ```
93
+
77
94
  [Faraday]: https://github.com/lostisland/faraday
78
95
 
79
96
  ## Development
data/lib/reamaze_api.rb CHANGED
@@ -30,6 +30,8 @@ module ReamazeAPI
30
30
  # :brand - Brand name (subdomain from your Reamaze URL)
31
31
  # :login - Reamaze login
32
32
  # :token - Reamaze API token
33
+ # block - Optional block that yields a Faraday::Connection instance
34
+ # (for customizing middleware, headers, etc)
33
35
  #
34
36
  # The credentials passed to the API can be configured globally via
35
37
  # `ReamazeAPI.config` or passed to this method. Credentials passed directly
@@ -38,7 +40,9 @@ module ReamazeAPI
38
40
  # Raises ArgumentError if a brand, login or token cannot be found.
39
41
  #
40
42
  # Returns a ReamazeAPI::Client instance.
41
- def self.new(**credentials)
42
- Client.new(**config.to_h.select { |_, value| value }.merge(credentials))
43
+ def self.new(**credentials, &block)
44
+ params = config.to_h.select { |_, value| value }.merge(credentials)
45
+
46
+ Client.new(**params, &block)
43
47
  end
44
48
  end
@@ -27,12 +27,19 @@ module ReamazeAPI
27
27
  # Returns a String.
28
28
  API_URL = "https://%{brand}.reamaze.com/api/v1".freeze
29
29
 
30
+ # Public: HTTP adapter used for API requests.
31
+ #
32
+ # Returns a Faraday::Connection.
33
+ attr_reader :http
34
+
30
35
  # Public: Initialize a new Client instance.
31
36
  #
32
37
  # brand: Brand name (subdomain from your Reamaze URL)
33
38
  # login: Reamaze login
34
39
  # token: Reamaze API token
35
40
  #
41
+ # Yields a Faraday::Connection if a block is given.
42
+ #
36
43
  # Returns nothing.
37
44
  def initialize(brand:, login:, token:)
38
45
  @url = URI.parse(API_URL % { brand: brand })
@@ -42,6 +49,8 @@ module ReamazeAPI
42
49
  builder.response :json
43
50
  builder.adapter Faraday.default_adapter
44
51
  builder.basic_auth login, token
52
+
53
+ yield builder if block_given?
45
54
  end
46
55
  end
47
56
 
@@ -1,3 +1,3 @@
1
1
  module ReamazeAPI
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reamaze_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Priddle