auto_ria_api 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: c8510748df81bd748312782710a402741ef40d43e1c99534074edcd6c99a3fbc
4
- data.tar.gz: 24dd5cf3ef295c3233aa4d3dc077189713db56840ea3e8acef5b43315959cfbc
3
+ metadata.gz: 8635fbea479db01d9e8530a65f4ad495e69adc0c22a28795f038029d5ac1af13
4
+ data.tar.gz: f9a5e97b35a6f3c9243accc396075134689bd8f8dc235604e9c09f90ebf3a1e9
5
5
  SHA512:
6
- metadata.gz: 33be752da4987dfc7dc6f8ffde4cb9b6c98f9e13ac44992d9fbb6ced4e09dfff64f6bd82fdc4ac4f65203ef890f9316c592850c019daeb5b8a33b1545fbd5d7e
7
- data.tar.gz: cd375a982d420af853b01dc1c4d347582446d027338a5c03a9f1011ec208bad2f3f19c63d52b38a9743aa58ec603c724dc69ae119fd666677f5c69e3c050bbd2
6
+ metadata.gz: d4e0c32bb7ca8db34bb9fb30bafe33ef953a3e275d6ecc8e49b6211b79b1e137e99b326384d043acec0fcc2218fea830dc9f97bcc3efe587bb0b5bafd9307c55
7
+ data.tar.gz: 4027e5bc143eaa35a068513b03824af36fb432fd6372cb2e8a66a37732f67935ef4539a32cdc93195ad232adb1c43fe976d2c0bbe5188b934746773bfa2c4152
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
data/README.md CHANGED
@@ -61,7 +61,7 @@ Help is appreciated Feel free to fork and make a difference!
61
61
 
62
62
  ## Tests
63
63
 
64
- Provide `ENV['AUTO_RIA_API_KEY']` in your `.env` file or add it to system env: `export AUTO_RIA_API_KEY=your_key` and run `rspec`
64
+ run `rspec`
65
65
 
66
66
  ## License
67
67
 
data/auto_ria_api.gemspec CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata['source_code_uri'] = 'https://github.com/drkmen/auto_ria_api'
22
22
  spec.metadata['changelog_uri'] = 'https://github.com/drkmen/auto_ria_api'
23
23
  else
24
- raise "RubyGems 2.0 or newer is required to protect against " \
25
- "public gem pushes."
24
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ 'public gem pushes.'
26
26
  end
27
27
 
28
28
  # Specify which files should be added to the gem when it is released.
@@ -30,11 +30,11 @@ Gem::Specification.new do |spec|
30
30
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
31
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
32
  end
33
- spec.bindir = "exe"
33
+ spec.bindir = 'exe'
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
- spec.require_paths = ["lib"]
35
+ spec.require_paths = ['lib']
36
36
 
37
- spec.add_development_dependency "bundler", "~> 1.17"
38
- spec.add_development_dependency "rake", "~> 10.0"
39
- spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency 'bundler', '~> 1.17'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
40
  end
data/lib/auto_ria_api.rb CHANGED
@@ -4,34 +4,43 @@ require 'json'
4
4
 
5
5
  module AutoRiaApi
6
6
  class Base
7
+ attr_accessor :api_key
8
+ attr_reader :default_url
9
+
10
+ DEFAULT_URL = 'https://developers.ria.com'.freeze
11
+
7
12
  def initialize(api_key:, url: nil)
8
- raise ArgumentError, 'API key should not be empty.' if blank?(api_key)
13
+ raise ArgumentError, 'API key should not be empty' if blank?(api_key)
14
+
9
15
  @api_key = api_key
10
- @default_url = url || 'https://developers.ria.com/'
16
+ @default_url = url || DEFAULT_URL
11
17
  end
12
18
 
13
19
  def types
14
20
  request '/auto/categories'
15
21
  end
16
22
 
17
- def carcasses(type:, grouped: false, all: false)
18
- raise ArgumentError, 'Type should not be empty.' if blank?(type)
19
- return request '/auto/bodystyles' if all
20
- group = '_group' if grouped
21
- request "/auto/categories/#{type}/bodystyles/#{group}"
23
+ def carcasses(type:, options: {})
24
+ raise ArgumentError, '`type` should not be empty' if blank?(type)
25
+ return request '/auto/bodystyles' if options[:all]
26
+
27
+ group = '/_group' if options[:grouped]
28
+ request "/auto/categories/#{type}/bodystyles#{group}"
22
29
  end
23
30
 
24
31
  def marks(type:)
25
- raise ArgumentError, 'Type should not be empty.' if blank?(type)
32
+ raise ArgumentError, '`type` should not be empty' if blank?(type)
33
+
26
34
  request "/auto/categories/#{type}/marks"
27
35
  end
28
36
 
29
- def models(type:, mark:, grouped: false, all: false)
30
- raise ArgumentError, 'Type should not be empty.' if blank?(type)
31
- raise ArgumentError, 'Mark should not be empty.' if blank?(mark)
32
- return request '/auto/models' if all
33
- group = '_group' if grouped
34
- request "/auto/categories/#{type}/marks/#{mark}/models/#{group}"
37
+ def models(type:, mark:, options: {})
38
+ raise ArgumentError, '`type` should not be empty' if blank?(type)
39
+ raise ArgumentError, '`mark` should not be empty' if blank?(mark)
40
+ return request '/auto/models' if options[:all]
41
+
42
+ group = options[:grouped] ? '/_group' : ''
43
+ request "/auto/categories/#{type}/marks/#{mark}/models" + group
35
44
  end
36
45
 
37
46
  def regions
@@ -39,17 +48,19 @@ module AutoRiaApi
39
48
  end
40
49
 
41
50
  def cities(region:)
42
- raise ArgumentError, 'Region should not be empty.' if blank?(region)
51
+ raise ArgumentError, '`region` should not be empty' if blank?(region)
52
+
43
53
  request "/auto/states/#{region}/cities"
44
54
  end
45
55
 
46
56
  def gearboxes(type:)
47
- raise ArgumentError, 'Type should not be empty.' if blank?(type)
57
+ raise ArgumentError, '`type` should not be empty' if blank?(type)
58
+
48
59
  request "/auto/categories/#{type}/gearboxes"
49
60
  end
50
61
 
51
62
  def driver_types
52
- raise 'Not implemented'
63
+ raise NotImplementedError
53
64
  end
54
65
 
55
66
  def fuels
@@ -61,40 +72,44 @@ module AutoRiaApi
61
72
  end
62
73
 
63
74
  def options(type:)
64
- raise ArgumentError, 'Type should not be empty.' if blank?(type)
75
+ raise ArgumentError, '`type` should not be empty' if blank?(type)
76
+
65
77
  request "/auto/categories/#{type}/auto_options"
66
78
  end
67
79
 
68
80
  def average_price(*args)
69
- raise 'Not implemented'
81
+ raise NotImplementedError
70
82
  end
71
83
 
72
84
  def search(*args)
73
- raise 'Not implemented'
85
+ raise NotImplementedError
74
86
  end
75
87
 
76
88
  def info(car_id:)
77
- raise ArgumentError, 'car_id should not be empty.' if blank?(car_id)
89
+ raise ArgumentError, '`car_id` should not be empty' if blank?(car_id)
90
+
78
91
  request '/auto/info', auto_id: car_id
79
92
  end
80
93
 
81
94
  def photos(car_id:)
82
- raise ArgumentError, 'car_id should not be empty.' if blank?(car_id)
95
+ raise ArgumentError, '`car_id` should not be empty' if blank?(car_id)
96
+
83
97
  request "/auto/fotos/#{car_id}", auto_id: car_id
84
98
  end
85
99
 
86
100
  private
87
101
 
88
102
  def request(url, params = {}, method = :get_response)
89
- uri = URI(@default_url + url)
90
- uri.query = URI.encode_www_form(params.merge(api_key: @api_key))
103
+ uri = URI(default_url + url)
104
+ uri.query = URI.encode_www_form(params.merge(api_key: api_key))
91
105
  response = Net::HTTP.public_send(method, uri)
92
106
  parsed response
93
107
  end
94
108
 
95
109
  def parsed(response)
96
110
  res = JSON.parse(response.body)
97
- raise Error, res.dig('error') if res.is_a?(Hash) && res.has_key?('error')
111
+ raise ResponseError, res.dig('error').to_s if res.is_a?(Hash) && res.has_key?('error')
112
+
98
113
  yield res if block_given?
99
114
  res
100
115
  end
@@ -104,5 +119,5 @@ module AutoRiaApi
104
119
  end
105
120
  end
106
121
 
107
- class Error < StandardError; end
122
+ class ResponseError < StandardError; end
108
123
  end
@@ -1,3 +1,3 @@
1
1
  module AutoRiaApi
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_ria_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - drkmen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-14 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler