service_api 0.0.9 → 0.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 +4 -4
- data/lib/service_api.rb +0 -1
- data/lib/service_api/version.rb +1 -1
- metadata +3 -10
- data/lib/service_api/normalize_options.rb +0 -75
- data/lib/service_api/normalize_options/base.rb +0 -11
- data/lib/service_api/normalize_options/hash_with_mapper_hash.rb +0 -11
- data/lib/service_api/normalize_options/normal_with_mapper_array.rb +0 -11
- data/lib/service_api/normalize_options/normal_with_mapper_hash.rb +0 -17
- data/spec/functionals/normalize_options.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86113e40634a4c9a9a16beff4a6c3aa5544b42cd
|
4
|
+
data.tar.gz: 585222ead342e420db33c69e8de93b0a7d1ef7c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54397f351d5c2e0aae047d6432f1862fffb245a6112840193aeb27d50d3dfa7d17ced4274d0290e2cf9cca0de994d9e0fb01b03747ed759b1fb2fc172d928b2a
|
7
|
+
data.tar.gz: 05452508d1eb522e01abc2e0a9794307c85623c60fdb617c87a6f9ddaf213327bd91ed9d32026c48d7287409ee8d8f4ea7b5660df08ab73d75964352681a6e68
|
data/lib/service_api.rb
CHANGED
data/lib/service_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Wawer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -136,16 +136,10 @@ files:
|
|
136
136
|
- Rakefile
|
137
137
|
- lib/service_api.rb
|
138
138
|
- lib/service_api/base_faraday.rb
|
139
|
-
- lib/service_api/normalize_options.rb
|
140
|
-
- lib/service_api/normalize_options/base.rb
|
141
|
-
- lib/service_api/normalize_options/hash_with_mapper_hash.rb
|
142
|
-
- lib/service_api/normalize_options/normal_with_mapper_array.rb
|
143
|
-
- lib/service_api/normalize_options/normal_with_mapper_hash.rb
|
144
139
|
- lib/service_api/uri_tokens.rb
|
145
140
|
- lib/service_api/version.rb
|
146
141
|
- service_api.gemspec
|
147
142
|
- spec/functionals/base_faraday_spec.rb
|
148
|
-
- spec/functionals/normalize_options.rb
|
149
143
|
- spec/functionals/uri_tokens_spec.rb
|
150
144
|
- spec/spec_helper.rb
|
151
145
|
homepage: http://github.com/wafcio/service_api
|
@@ -168,12 +162,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
162
|
version: '0'
|
169
163
|
requirements: []
|
170
164
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.4.5
|
172
166
|
signing_key:
|
173
167
|
specification_version: 4
|
174
168
|
summary: Set of useful modules, classes for api gems
|
175
169
|
test_files:
|
176
170
|
- spec/functionals/base_faraday_spec.rb
|
177
|
-
- spec/functionals/normalize_options.rb
|
178
171
|
- spec/functionals/uri_tokens_spec.rb
|
179
172
|
- spec/spec_helper.rb
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'service_api/normalize_options/base'
|
2
|
-
require 'service_api/normalize_options/hash_with_mapper_hash'
|
3
|
-
require 'service_api/normalize_options/normal_with_mapper_array'
|
4
|
-
require 'service_api/normalize_options/normal_with_mapper_hash'
|
5
|
-
|
6
|
-
class NormalizeOptions
|
7
|
-
attr_reader :mapper, :options
|
8
|
-
|
9
|
-
def initialize(mapper, *options)
|
10
|
-
@mapper = mapper
|
11
|
-
@options = options
|
12
|
-
end
|
13
|
-
|
14
|
-
def call
|
15
|
-
if hash_options?
|
16
|
-
parse_hash_options
|
17
|
-
elsif arguments_count_corrent?
|
18
|
-
parse_normal_options
|
19
|
-
else
|
20
|
-
raise ArgumentError
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def parse_hash_options
|
27
|
-
if mapper_hash?
|
28
|
-
parse_hash_options_with_mapper_hash
|
29
|
-
else
|
30
|
-
first_options
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse_normal_options
|
35
|
-
if mapper_hash?
|
36
|
-
parse_normal_options_with_mapper_hash
|
37
|
-
elsif mapper_array?
|
38
|
-
parse_normal_options_with_mapper_array
|
39
|
-
else
|
40
|
-
{}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def parse_hash_options_with_mapper_hash
|
45
|
-
NormalizeOptions::HashWithMapperHash.new(first_options, mapper).call
|
46
|
-
end
|
47
|
-
|
48
|
-
def parse_normal_options_with_mapper_hash
|
49
|
-
NormalizeOptions::NormalWithMapperHash.new(options, mapper).call
|
50
|
-
end
|
51
|
-
|
52
|
-
def parse_normal_options_with_mapper_array
|
53
|
-
NormalizeOptions::NormalWithMapperArray.new(options, mapper).call
|
54
|
-
end
|
55
|
-
|
56
|
-
def mapper_hash?
|
57
|
-
mapper.class == Hash
|
58
|
-
end
|
59
|
-
|
60
|
-
def mapper_array?
|
61
|
-
mapper.class == Array
|
62
|
-
end
|
63
|
-
|
64
|
-
def first_options
|
65
|
-
@first_options ||= options.first
|
66
|
-
end
|
67
|
-
|
68
|
-
def hash_options?
|
69
|
-
options.count == 1 && first_options.class == Hash
|
70
|
-
end
|
71
|
-
|
72
|
-
def arguments_count_corrent?
|
73
|
-
options.count == mapper.count
|
74
|
-
end
|
75
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class NormalizeOptions
|
2
|
-
class NormalWithMapperHash < NormalizeOptions::Base
|
3
|
-
def call
|
4
|
-
options.each_with_index do |option, index|
|
5
|
-
new_options[mapper[mapper_key[index]]] = option
|
6
|
-
end
|
7
|
-
|
8
|
-
new_options
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def mapper_key
|
14
|
-
mapper.keys
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe NormalizeOptions do
|
4
|
-
describe 'hash options' do
|
5
|
-
it 'return hash with mapped keys' do
|
6
|
-
expect(NormalizeOptions.new({ e1: :o1, e2: :o2 }, e1: 'test1', e2: 'test2').parse).to eq(o1: 'test1', o2: 'test2')
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'return original hash' do
|
10
|
-
expect(NormalizeOptions.new([:e1, :e2], e1: 'test1', e2: 'test2').parse).to eq(e1: 'test1', e2: 'test2')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'normal options' do
|
15
|
-
it 'return hash with mapped keys' do
|
16
|
-
expect(NormalizeOptions.new({ e1: :o1, e2: :o2 }, 'test1', 'test2').parse).to eq(o1: 'test1', o2: 'test2')
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'return correct hash' do
|
20
|
-
expect(NormalizeOptions.new([:e1, :e2], 'test1', 'test2').parse).to eq(e1: 'test1', e2: 'test2')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|