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 +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/auto_ria_api.gemspec +7 -7
- data/lib/auto_ria_api.rb +41 -26
- data/lib/auto_ria_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8635fbea479db01d9e8530a65f4ad495e69adc0c22a28795f038029d5ac1af13
|
4
|
+
data.tar.gz: f9a5e97b35a6f3c9243accc396075134689bd8f8dc235604e9c09f90ebf3a1e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e0c32bb7ca8db34bb9fb30bafe33ef953a3e275d6ecc8e49b6211b79b1e137e99b326384d043acec0fcc2218fea830dc9f97bcc3efe587bb0b5bafd9307c55
|
7
|
+
data.tar.gz: 4027e5bc143eaa35a068513b03824af36fb432fd6372cb2e8a66a37732f67935ef4539a32cdc93195ad232adb1c43fe976d2c0bbe5188b934746773bfa2c4152
|
data/Gemfile
CHANGED
data/README.md
CHANGED
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
|
25
|
-
|
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 =
|
33
|
+
spec.bindir = 'exe'
|
34
34
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
-
spec.require_paths = [
|
35
|
+
spec.require_paths = ['lib']
|
36
36
|
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
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
|
13
|
+
raise ArgumentError, 'API key should not be empty' if blank?(api_key)
|
14
|
+
|
9
15
|
@api_key = api_key
|
10
|
-
@default_url = url ||
|
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:,
|
18
|
-
raise ArgumentError, '
|
19
|
-
return request '/auto/bodystyles' if all
|
20
|
-
|
21
|
-
|
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, '
|
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:,
|
30
|
-
raise ArgumentError, '
|
31
|
-
raise ArgumentError, '
|
32
|
-
return request '/auto/models' if all
|
33
|
-
|
34
|
-
|
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, '
|
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, '
|
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
|
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, '
|
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
|
81
|
+
raise NotImplementedError
|
70
82
|
end
|
71
83
|
|
72
84
|
def search(*args)
|
73
|
-
raise
|
85
|
+
raise NotImplementedError
|
74
86
|
end
|
75
87
|
|
76
88
|
def info(car_id:)
|
77
|
-
raise ArgumentError, 'car_id should not be empty
|
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
|
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(
|
90
|
-
uri.query = URI.encode_www_form(params.merge(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
|
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
|
122
|
+
class ResponseError < StandardError; end
|
108
123
|
end
|
data/lib/auto_ria_api/version.rb
CHANGED
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
|
+
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:
|
11
|
+
date: 2020-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|