api_client_base 1.0.0 → 1.1.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: 4234cdffb4d3eeb776cde23fdaa8006ce003443d
4
- data.tar.gz: 57fee9ecd1d7daaa2266b765eeb3c2a158dfd999
3
+ metadata.gz: 2d4ac34888af5202ce65d67d0611455fd1bbe786
4
+ data.tar.gz: 2c7f6b11e8ad2eb056a7b2399be312ad834f8800
5
5
  SHA512:
6
- metadata.gz: d7a9209a13b42cf19c941842370fd63309debcacf762e10d6a1b93ef7d56a70f020b5becfeeea75535cbc47508aab7f0f042fe3bd5c2190dfe4b0539a3ced3bd
7
- data.tar.gz: a18e71f2d598f0db601a93f7bdc8be6395be335bb4f100ad4793a06b01cf28845f1b75c1dafc29f3b9fe501ec213cd46d7426801c08381ef14a4b83271cfa4cf
6
+ metadata.gz: bcc5bd5089efd35cbc15146fab4dc7f48fc38ecf6b84ce41e292c827a84fca5915d7df27535add568b01ac706f52df68e1e8c921d5da47a4445d90a64c77a378
7
+ data.tar.gz: eba55cbe3023f372036c6b7251df20da26a0d9786ba43e6cf28c5b94b7d5a3d9065a9bb428e279bf5a37d01bbf303ad52def5c97bd85aa9ebd52b1f288fad5c8
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [1.1.0] - 2017-02-17
8
+ ### Added
9
+ - `Client` inherits attributes from gem namespace. No need to specify these attributes again.
10
+
7
11
  ## [1.0.0] - 2017-02-15
8
12
  ### Fixed
9
13
  - Ensure args are passed correctly into request instantiation
data/README.md CHANGED
@@ -25,7 +25,7 @@ module MyGem
25
25
  include APIClientBase::Base.module
26
26
 
27
27
  with_configuration do
28
- has :host, classes: String
28
+ has :host, classes: String, default: "https://production.com"
29
29
  has :username, classes: String
30
30
  has :password, classes: String
31
31
  end
@@ -48,26 +48,38 @@ end
48
48
 
49
49
  #### Default Options
50
50
 
51
+ Given this config:
52
+
53
+ ```ruby
54
+ module MyGem
55
+ include APIClientBase::Base.module
56
+
57
+ with_configuration do
58
+ has :host, classes: String, default: "https://production.com"
59
+ has :username, classes: String
60
+ has :password, classes: String
61
+ end
62
+ end
63
+ ```
64
+
65
+ Configure the `Client` like this:
66
+
51
67
  ```ruby
52
68
  module MyGem
53
69
  class Client
54
70
  # specifying a symbol for `default_opts` will look for a method of that name
55
71
  # and pass that into the request
56
- HOST = "https://production.com"
57
72
  include APIClientBase::Client.module(default_opts: :default_opts)
58
73
 
59
74
  private
60
75
 
61
76
  def default_opts
62
- # At least include `host`. Other things you may need to include: `token`, `secret`
63
- { host: HOST, secret: MyGem.configuration.secret }
77
+ # Pass along all the things your requests need.
78
+ # The methods `host`, `username`, and `password` are available
79
+ # to your `Client` instance because it inherited these from the configuration.
80
+ { host: host, username: username, password: password }
64
81
  end
65
82
  end
66
-
67
- class Client
68
- HOST = "https://production.com"
69
- include APIClientBase::Client.module(default_opts: {host: HOST})
70
- end
71
83
  end
72
84
  ```
73
85
 
@@ -8,6 +8,7 @@ require "api_client_base/version"
8
8
  require "api_client_base/base"
9
9
  require "api_client_base/base/class_methods"
10
10
  require "api_client_base/client"
11
+ require "api_client_base/client/attributes"
11
12
  require "api_client_base/client/class_methods"
12
13
  require "api_client_base/request"
13
14
  require "api_client_base/response"
@@ -20,6 +20,7 @@ module APIClientBase
20
20
  extend ActiveSupport::Concern
21
21
 
22
22
  included do
23
+ include APIClientBase::Client::Attributes
23
24
  extend APIClientBase::Client::ClassMethods
24
25
  end
25
26
 
@@ -0,0 +1,26 @@
1
+ module APIClientBase
2
+ module Client
3
+ module Attributes
4
+
5
+ def self.included(base)
6
+ base.include Virtus.model
7
+ inherit_attributes!(base)
8
+ end
9
+
10
+ private
11
+
12
+ def self.inherit_attributes!(klass)
13
+ parent_module = klass.name.deconstantize.constantize
14
+ return unless parent_module.respond_to?(:configuration)
15
+ parent_module.configuration.rules.each do |rule|
16
+ self.inherit_attribute!(klass, rule)
17
+ end
18
+ end
19
+
20
+ def self.inherit_attribute!(klass, rule)
21
+ klass.attribute rule[0]
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module APIClientBase
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_client_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-15 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -159,6 +159,7 @@ files:
159
159
  - lib/api_client_base/base.rb
160
160
  - lib/api_client_base/base/class_methods.rb
161
161
  - lib/api_client_base/client.rb
162
+ - lib/api_client_base/client/attributes.rb
162
163
  - lib/api_client_base/client/class_methods.rb
163
164
  - lib/api_client_base/request.rb
164
165
  - lib/api_client_base/response.rb