artirix_data_models 0.6.3.1 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bf75f8fabe2f1161d1306a0c1d1da33abc2e178
4
- data.tar.gz: 033a3edd3d4ec0c2cb5158ec3fda73a05e9a6c7f
3
+ metadata.gz: cacb0976cda27f75c2646ca38836457d6e48af28
4
+ data.tar.gz: 1427115dc8b1cf019e2adaa8fb6aca3c9d68e417
5
5
  SHA512:
6
- metadata.gz: 8957ef6dae32230c8dd3c7223f8b2473fba7f70f969cd0585d53bf0008d62b9164d158b1e2fd0c30e19c0c4c5a77e1ff3f71b0c2b060de137725e695faf81e35
7
- data.tar.gz: f26f34e27de7508872b7b5ca6a6f8d0a36f740848b6bd900aa6449d21738e975b67a66e1970eb39a25504152fbc92b6074adfce1fc64ca49f85715cff59ac80a
6
+ metadata.gz: edf05df3fc6916f662f0e1476af6940f95e0fb6227882cc180b6cb4372f8706a99eeb0f39bff7c106b135a3042425e5b9ccad54a986b56d4832558b78fb800e9
7
+ data.tar.gz: f8c13e33e16c6a5e7b4c325ffa2fa63f145de85a9f4a3250a9fe269f4c4026247d679148bf8fdeb3c43de5e7792b44d069d50fd2a9e3652b8a468dcd6ddc52e6
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development, :test do
7
+ gem 'rubocop'
7
8
  gem 'pry'
8
9
  gem 'pry-nav'
9
10
  gem 'pry-stack_explorer'
data/README.md CHANGED
@@ -7,12 +7,12 @@
7
7
  [![Code Climate Coverage](https://codeclimate.com/github/artirix/artirix_data_models/coverage.png)](https://codeclimate.com/github/artirix/artirix_data_models)
8
8
 
9
9
 
10
- This gem provides the tools for building Data Models (ActiveModel compliant objects that only receive attributes on initialisation),
11
- with their DAOs (Data Access Objects, the ones responsible for loading them up), the EsCollection objects (collection of
10
+ This gem provides the tools for building Data Models (ActiveModel compliant objects that only receive attributes on initialisation),
11
+ with their DAOs (Data Access Objects, the ones responsible for loading them up), the EsCollection objects (collection of
12
12
  objects, paginatable and with extra features), and tools that allow them to work.
13
13
 
14
14
  Its goal is to provide a set of Read Only model objects that receive their data from some sort of Data API.
15
-
15
+
16
16
  It's designed to work assuming JSON APIs and ElasticSearch responses.
17
17
 
18
18
  # TODO:
@@ -22,6 +22,32 @@ It's designed to work assuming JSON APIs and ElasticSearch responses.
22
22
 
23
23
  ## Usage
24
24
 
25
+ ### Connection
26
+
27
+ You have to specify the location of data-layer. It can be done in the config like this:
28
+
29
+ ```ruby
30
+ SimpleConfig.for(:site) do
31
+ group :data_gateway do
32
+ set :url, 'http://super-secure-domain-123456.com'
33
+ end
34
+ end
35
+ ```
36
+
37
+ If the connection is covered by basic authentication it can be set by adding ```login``` and ```password``` settings.
38
+
39
+ Example:
40
+
41
+ ```ruby
42
+ SimpleConfig.for(:site) do
43
+ group :data_gateway do
44
+ set :url, 'http://super-secure-domain-123456.com'
45
+ set :login, 'WhiteCat'
46
+ set :password, 'B@dPassword!'
47
+ end
48
+ end
49
+ ```
50
+
25
51
  ### Model
26
52
 
27
53
  TODO:
@@ -40,7 +66,7 @@ TODO:
40
66
 
41
67
  ### The Registry
42
68
 
43
- Your app should extend the `ArtirixDataModels::DAORegistry`. We can override the `setup_config` method to add extra loaders.
69
+ Your app should extend the `ArtirixDataModels::DAORegistry`. We can override the `setup_config` method to add extra loaders.
44
70
 
45
71
  **important: do not forget to call `super` on `setup_config`.**
46
72
 
@@ -70,7 +96,7 @@ end
70
96
 
71
97
  ### initializer
72
98
 
73
- An initializer should be added for extra configuration.
99
+ An initializer should be added for extra configuration.
74
100
 
75
101
  We can enable pagination with either `will_paginate` or `kaminari`.
76
102
 
@@ -153,8 +179,8 @@ end
153
179
  #### Custom DAO Registry
154
180
 
155
181
  For the use of a custom DAO Registry, it is recomended to actually require it on the test helper:
156
-
157
-
182
+
183
+
158
184
  in spec/rails_helper.rb:
159
185
 
160
186
  ```ruby
@@ -194,7 +220,7 @@ end
194
220
  In order to use FactoryGirl with these Models, we need to specify:
195
221
 
196
222
  1. the objects cannot be saved, so we need to specify `skip_create` to avoid it.
197
- 2. the setting of the data is only to be done on the model's initialisation, not with public setters.
223
+ 2. the setting of the data is only to be done on the model's initialisation, not with public setters.
198
224
  For that, we need to specify: `initialize_with { new(attributes) }`
199
225
 
200
226
  ```ruby
@@ -203,11 +229,11 @@ FactoryGirl.define do
203
229
  factory :article do
204
230
  # no save call
205
231
  skip_create
206
-
232
+
207
233
  # in our models we have private setters -> we need the attributes to be
208
234
  # passed on object initialisation
209
235
  initialize_with { new(attributes) }
210
-
236
+
211
237
  sequence(:id)
212
238
  title { Faker::Lorem.sentence }
213
239
  end
@@ -224,6 +250,10 @@ end
224
250
 
225
251
  ## Changes
226
252
 
253
+ ### 0.6.4
254
+
255
+ - Add ability to create connection to data source using HTTP Basic Authentication.
256
+
227
257
  ### 0.6.3.1
228
258
 
229
259
  - Fix in EsCollection's aggregation parsing (nested + single from RAW now work ok)
@@ -253,7 +283,7 @@ Yanked because of typo bug on SortedBucketAggregationBase. Released 0.6.3.1 with
253
283
  - `SortedBucketAggregationBase` introduced. now `ArtirixDataModels::AggregationsFactory.sorted_aggregation_class_based_on_index_on(index_array)` available to create a class for Aggregations which will sort the buckets based on the position of the elements on a given array.
254
284
 
255
285
 
256
- ### ~0.6.1~
286
+ ### ~0.6.1~
257
287
 
258
288
  Yanked because of breaking change introduction: removal of `Aggregation.from_json` method
259
289
 
@@ -104,18 +104,36 @@ class ArtirixDataModels::DataGateway
104
104
  end
105
105
 
106
106
  module DefaultConnectionLoader
107
- def self.default_connection
108
- url = config_connection_url
109
- Faraday.new(url: url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
110
- faraday.request :url_encoded # form-encode POST params
111
- faraday.response :logger # log requests to STDOUT
112
- faraday.adapter Faraday.default_adapter
107
+
108
+ class << self
109
+ attr_accessor :config
110
+
111
+ def default_connection
112
+ url = connection_url
113
+
114
+ Faraday.new(url: url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
115
+ faraday.request :url_encoded # form-encode POST params
116
+ faraday.response :logger # log requests to STDOUT
117
+ faraday.basic_auth(config.login, config.password) if basic_auth?
118
+ faraday.adapter Faraday.default_adapter
119
+ end
113
120
  end
114
- end
115
121
 
116
- def self.config_connection_url
117
- SimpleConfig.for(:site).data_gateway.url
122
+ # Configuration access
123
+
124
+ def config
125
+ @config ||= SimpleConfig.for(:site).data_gateway
126
+ end
127
+
128
+ def connection_url
129
+ config.url
130
+ end
131
+
132
+ def basic_auth?
133
+ config.respond_to?(:login) && config.respond_to?(:password)
134
+ end
118
135
  end
136
+
119
137
  end
120
138
 
121
139
  class Error < StandardError
@@ -1,3 +1,3 @@
1
1
  module ArtirixDataModels
2
- VERSION = '0.6.3.1'
2
+ VERSION = '0.6.4'
3
3
  end
@@ -17,6 +17,30 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
17
17
  When(:gateway) { described_class.new }
18
18
  Then { gateway.connection.url_prefix.to_s == connection_url }
19
19
  end
20
+
21
+ context 'basic auth connection' do
22
+ Given(:connection_url) { 'http://example.com/other' }
23
+ Given(:basic_login) { 'WhiteCat' }
24
+ Given(:basic_password) { 'B@dPassword!' }
25
+
26
+ Given do
27
+ url = connection_url
28
+ login = basic_login
29
+ password = basic_password
30
+
31
+ SimpleConfig.for(:site) do
32
+ group :data_gateway do
33
+ set :url, url
34
+ set :login, login
35
+ set :password, password
36
+ end
37
+ end
38
+ end
39
+
40
+ When(:gateway) { described_class.new }
41
+ Then { expect(gateway.connection.url_prefix.to_s).to eq(connection_url) }
42
+ Then { expect(gateway.connection.headers).to have_key('Authorization') }
43
+ end
20
44
  end
21
45
 
22
46
  context 'requests' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artirix_data_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3.1
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport