transparent_data-rb 0.1.0 → 0.1.6

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
  SHA256:
3
- metadata.gz: 3d6324a6d674bfe9b41b0f5265814278ac6896e1b5f8d81f47182a98e0e6b55f
4
- data.tar.gz: c9f116dcb04e6e8bdf9a53eb6e2ab8b1dbfc23078b886e2a40a3168b0ee76712
3
+ metadata.gz: c5af41cd1106275ad10b7ca0eafa1871651d4967ba1e1a6f00d04fa826ca01b9
4
+ data.tar.gz: 9d0a797a052a03d8cb57e4faba99fa094c3cc29017804d2a4f9d91e3095a5454
5
5
  SHA512:
6
- metadata.gz: 0c37b343915a9aa87faeec773c3e44c0ea730ce72a474519ca9cd4d6db392de844e25e5c337597380eac33cfe3ffa58e89a033cbde2d2ad3f5bdc53041d53159
7
- data.tar.gz: c29f27c94b096d5caca03a5dbc5d9b2972e1b8bfa8fd7860d05e106f98a670976d8e28a92fbd082ae4d51e6afeb668f24a205558b5c9ce4f0c08ea5257231d1a
6
+ metadata.gz: 183407be095e12dee5d5fc0fd3a6a9357f1992f08bd6375d38e109e4f0523b8b6eed3fd069984712126c3bd3c4beb2ef5aceba7ae61dc864b8806960c2a88dd7
7
+ data.tar.gz: 2a7f1b56290e4a9331f32df1025acf481588cb5c7460714cb85035ac572807c43861a2aed8368ae9023c1d9a66ae56a37cfb41ed0504a26da55f4d32ac1949ed
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ transparent_data-rb-*.gem
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transparent_data-rb (0.0.1)
4
+ transparent_data-rb (0.1.6)
5
5
  bundler (~> 2.1)
6
6
  faraday
7
7
  rake (~> 13.0)
data/README.md CHANGED
@@ -1,44 +1,56 @@
1
- # TransparentData
1
+ # TransparentData RB
2
+ [![Gem Version](https://badge.fury.io/rb/transparent_data-rb.svg)](https://badge.fury.io/rb/transparent_data-rb) [![Build Status](https://travis-ci.com/sigmen/transparent_data-rb.svg?branch=master)](https://travis-ci.com/sigmen/transparent_data-rb)
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/transparent_data`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ ## Supports
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ Ruby `>= 2.4`.
6
7
 
7
8
  ## Installation
8
9
 
9
10
  Add this line to your application's Gemfile:
10
11
 
11
- ```ruby
12
- gem 'transparent_data-rb'
13
- ```
12
+ gem 'transparent_data-rb'
14
13
 
15
14
  And then execute:
16
15
 
17
16
  $ bundle install
18
17
 
19
- Or install it yourself as:
18
+ Or install with:
20
19
 
21
20
  $ gem install transparent_data-rb
22
21
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
22
+ ### Usage
30
23
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
24
+ ```ruby
25
+ response = TransparentData.search(country_name, query)
34
26
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/transparent_data-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/transparent_data-rb/blob/master/CODE_OF_CONDUCT.md).
27
+ response.body # => [{...}]
28
+ response.status # => 200
29
+ response.headers # => {...}
30
+ ```
36
31
 
32
+ #### Search options
33
+ * country_name - Any available country name (see Available countries)
34
+ * query - Search query
37
35
 
38
- ## License
36
+ #### Available countries
37
+ Gem supports all available Transparentdata.eu countries:
38
+ * finland
39
+ * uk
40
+ * denmark
41
+ * norway
42
+ * slovakia
43
+ * czech
39
44
 
40
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+ #### Configuration
41
46
 
42
- ## Code of Conduct
47
+ Before using gem you need to configure some parameters:
43
48
 
44
- Everyone interacting in the TransparentData project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/transparent_data-rb/blob/master/CODE_OF_CONDUCT.md).
49
+ ```ruby
50
+ TransparentData.configure do |config|
51
+ config.url = 'https://transparentdata.eu/' # You can using any another url for test environment
52
+ config.user = 'user' # Username for HTTP Basic
53
+ config.password = 'password' # Password for HTTP Basic
54
+ config.key = 'key' # API Key
55
+ end
56
+ ```
@@ -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
@@ -14,7 +14,7 @@ module TransparentData
14
14
  end
15
15
 
16
16
  define_singleton_method("#{attr}=") do |value|
17
- public_send(attr) || instance_variable_set("@#{attr}", value)
17
+ instance_variable_get("@#{attr}") || instance_variable_set("@#{attr}", value)
18
18
  end
19
19
  end
20
20
  end
@@ -1,9 +1,20 @@
1
1
  require 'transparent_data/request'
2
+ require 'transparent_data/actions/search'
3
+ require 'transparent_data/actions/add'
4
+ require 'transparent_data/actions/result'
2
5
 
3
6
  module TransparentData
4
7
  module ModuleFunctions
5
- def search(country, query)
6
- TransparentData::Request.call(client, country, query)
8
+ def search(country, query_str)
9
+ TransparentData::Actions::Search.new(client, country, query_str).call
10
+ end
11
+
12
+ def add(source, method, parameters)
13
+ TransparentData::Actions::Add.new(client, source, method, parameters).call
14
+ end
15
+
16
+ def result(ident)
17
+ TransparentData::Actions::Result.new(client, ident).call
7
18
  end
8
19
 
9
20
  private
@@ -2,33 +2,24 @@ require 'transparent_data/response/struct'
2
2
 
3
3
  module TransparentData
4
4
  class Request
5
- QUERY_PARAM = :q
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(country, query)
25
- "/#{TransparentData.key}/#{fetch_country_id(country)}Search?#{QUERY_PARAM}=#{query}"
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 fetch_country_id(country)
29
- COUNTRY_TO_KEY_MAP.fetch(country.to_sym) do
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, :body, :headers, :status
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
@@ -1,3 +1,3 @@
1
1
  module TransparentData
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Roman Kakorin']
10
10
  spec.email = ['romchky1@gmail.com']
11
11
 
12
- spec.summary = 'Gem implements multitable iheritance.'
13
- spec.description = 'Gem implements multitable iheritance.'
12
+ spec.summary = 'https://transparentdata.eu API client'
13
+ spec.description = 'https://transparentdata.eu API client'
14
14
  spec.homepage = 'https://github.com/sigmen/transparent_data-rb'
15
15
  spec.license = 'MIT'
16
16
  spec.required_ruby_version = '>= 2.4.0'
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.0
4
+ version: 0.1.6
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-21 00:00:00.000000000 Z
11
+ date: 2020-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Gem implements multitable iheritance.
97
+ description: https://transparentdata.eu API client
98
98
  email:
99
99
  - romchky1@gmail.com
100
100
  executables: []
@@ -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
@@ -146,5 +149,5 @@ requirements: []
146
149
  rubygems_version: 3.1.4
147
150
  signing_key:
148
151
  specification_version: 4
149
- summary: Gem implements multitable iheritance.
152
+ summary: https://transparentdata.eu API client
150
153
  test_files: []