transparent_data-rb 0.1.3 → 0.1.4
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/Gemfile.lock +1 -1
- data/README.md +1 -3
- data/lib/transparent_data.rb +2 -0
- data/lib/transparent_data/actions/add.rb +28 -0
- data/lib/transparent_data/actions/result.rb +22 -0
- data/lib/transparent_data/actions/search.rb +40 -0
- data/lib/transparent_data/module_functions.rb +10 -2
- data/lib/transparent_data/request.rb +10 -19
- data/lib/transparent_data/response/struct.rb +7 -1
- data/lib/transparent_data/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a46655327640a1c8d2bf6c73418692c2f962add03aab036551c89aeb966d972
|
4
|
+
data.tar.gz: fc85f512554cea23a73e27ceff5855c4d78f7f93280ea5b48277a8e93ace15f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f74412f2aef37f3af6c2ce6fb38798239ee6fd7aa706752f68d1770ee9e34844e1249877f5dca1935fe687ed51931165dd522de2d05c528a71613694d972313
|
7
|
+
data.tar.gz: d9b697e8c885558e79dc95ace299695bab5314af77de0849314248d8eb9a6d9191d1b9a9375f1077d5dcc901d20fa0805773aff41c1a8d1d6c2a861debb12c4c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# TransparentData RB
|
2
2
|
[](https://badge.fury.io/rb/transparent_data-rb) [](https://travis-ci.com/sigmen/transparent_data-rb)
|
3
3
|
|
4
|
-
# UNDER DEVELOPMENT
|
5
|
-
|
6
4
|
## Supports
|
7
5
|
|
8
6
|
Ruby `>= 2.4`.
|
data/lib/transparent_data.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
require 'transparent_data/version'
|
4
5
|
require 'transparent_data/exceptions'
|
5
6
|
require 'transparent_data/configurable'
|
7
|
+
require 'transparent_data/request'
|
6
8
|
require 'transparent_data/module_functions'
|
7
9
|
|
8
10
|
module TransparentData
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module TransparentData
|
2
|
+
module Actions
|
3
|
+
class Add
|
4
|
+
attr_reader :client, :source, :method, :parameters
|
5
|
+
|
6
|
+
def initialize(client, source, method, parameters)
|
7
|
+
@client = client
|
8
|
+
@source = source
|
9
|
+
@method = method
|
10
|
+
@parameters = parameters
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
TransparentData::Request.call(client, 'add', json: build_json)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def build_json
|
20
|
+
{
|
21
|
+
source: source,
|
22
|
+
method: method,
|
23
|
+
parameters: parameters
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module TransparentData
|
2
|
+
module Actions
|
3
|
+
class Result
|
4
|
+
attr_reader :client, :ident
|
5
|
+
|
6
|
+
def initialize(client, ident)
|
7
|
+
@client = client
|
8
|
+
@ident = ident
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
TransparentData::Request.call(client, 'result', query: build_query(ident))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_query
|
18
|
+
{ ident: ident }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module TransparentData
|
2
|
+
module Actions
|
3
|
+
class Search
|
4
|
+
COUNTRY_TO_KEY_MAP = {
|
5
|
+
finland: :fi,
|
6
|
+
czech: :cz,
|
7
|
+
denmark: :dk,
|
8
|
+
norway: :no,
|
9
|
+
slovakia: :sk,
|
10
|
+
uk: :uk
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
attr_reader :client, :country, :query_str
|
14
|
+
|
15
|
+
def initialize(client, country, query_str)
|
16
|
+
@client = client
|
17
|
+
@country = country
|
18
|
+
@query_str = query_str
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
search_method = "#{fetch_country_id(country)}Search"
|
23
|
+
|
24
|
+
TransparentData::Request.call(client, search_method, query: build_query(query_str))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_query(query_str)
|
30
|
+
{ q: query_str }
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch_country_id(country)
|
34
|
+
COUNTRY_TO_KEY_MAP.fetch(country.to_s.downcase.to_sym) do
|
35
|
+
raise TransparentData::UnknownCountryError, "Unknown country: #{country.inspect}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -2,8 +2,16 @@ require 'transparent_data/request'
|
|
2
2
|
|
3
3
|
module TransparentData
|
4
4
|
module ModuleFunctions
|
5
|
-
def search(country,
|
6
|
-
TransparentData::
|
5
|
+
def search(country, query_str)
|
6
|
+
TransparentData::Actions::Search.new(client, country, query_str).call
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(source, method, parameters)
|
10
|
+
TransparentData::Actions::Add.new(client, source, method, parameters).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def result(ident)
|
14
|
+
TransparentData::Actions::Result.new(client, ident).call
|
7
15
|
end
|
8
16
|
|
9
17
|
private
|
@@ -2,33 +2,24 @@ require 'transparent_data/response/struct'
|
|
2
2
|
|
3
3
|
module TransparentData
|
4
4
|
class Request
|
5
|
-
|
6
|
-
|
7
|
-
COUNTRY_TO_KEY_MAP = {
|
8
|
-
finland: :fi,
|
9
|
-
czech: :cz,
|
10
|
-
denmark: :dk,
|
11
|
-
norway: :no,
|
12
|
-
slovakia: :sk,
|
13
|
-
uk: :uk
|
14
|
-
}.freeze
|
15
|
-
|
16
|
-
def self.call(client, country, query)
|
17
|
-
response = client.post(build_path(country, query))
|
5
|
+
def self.call(client, method, query: {}, json: {})
|
6
|
+
response = client.post(build_path(method, query), json)
|
18
7
|
|
19
8
|
TransparentData::Response::Struct.new(response)
|
20
9
|
end
|
21
10
|
|
22
11
|
private
|
23
12
|
|
24
|
-
def build_path(
|
25
|
-
"/#{TransparentData.key}/#{
|
13
|
+
def build_path(method, query)
|
14
|
+
base_path = "/#{TransparentData.key}/#{method}"
|
15
|
+
|
16
|
+
return base_path unless query&.any?
|
17
|
+
|
18
|
+
base_path.concat("?#{convert_params_to_query(query)}")
|
26
19
|
end
|
27
20
|
|
28
|
-
def
|
29
|
-
|
30
|
-
raise TransparentData::UnknownCountryError, "Unknown country: #{country.inspect}"
|
31
|
-
end
|
21
|
+
def convert_params_to_query(params)
|
22
|
+
params.map { |pair| pair.join('=') }.join('&')
|
32
23
|
end
|
33
24
|
end
|
34
25
|
end
|
@@ -3,11 +3,17 @@ module TransparentData
|
|
3
3
|
class Struct
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
-
def_delegators :@response, :
|
6
|
+
def_delegators :@response, :headers, :status, :success?
|
7
7
|
|
8
8
|
def initialize(response)
|
9
9
|
@response = response
|
10
10
|
end
|
11
|
+
|
12
|
+
def body
|
13
|
+
JSON.parse(@response.body)
|
14
|
+
rescue JSON::ParserError
|
15
|
+
@response.body
|
16
|
+
end
|
11
17
|
end
|
12
18
|
end
|
13
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transparent_data-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kakorin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,9 @@ files:
|
|
114
114
|
- bin/console
|
115
115
|
- bin/setup
|
116
116
|
- lib/transparent_data.rb
|
117
|
+
- lib/transparent_data/actions/add.rb
|
118
|
+
- lib/transparent_data/actions/result.rb
|
119
|
+
- lib/transparent_data/actions/search.rb
|
117
120
|
- lib/transparent_data/configurable.rb
|
118
121
|
- lib/transparent_data/exceptions.rb
|
119
122
|
- lib/transparent_data/module_functions.rb
|