auto_ria_api 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +58 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +14 -11
- data/auto_ria_api.gemspec +7 -7
- data/lib/auto_ria_api.rb +55 -34
- data/lib/auto_ria_api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8ab0dcbe23001fb09d111b0ec606aa294c36b3127d12305e34b6e56ff006cf9
|
4
|
+
data.tar.gz: 86482a3933c9471daa342de07f7fcb27432beb7888f48f54d8b8657bf3970464
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a920fe0b529b321c8afd3579b2b1079c8fa0e20dcd1260a198a82d6de74765bea89e3dc211b03161096356402614847f1902cd4e7d2561217b52b90a4fde0a7
|
7
|
+
data.tar.gz: 53ac1564848628d3fbe1749dfa86452ff4a4f0bee6707276ab38bef2623d77fc46c18486bcf46927858c10c71fd2f5ef5e3ad57ddffc4b58a89226901f137cf5
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#inherit_from: .rubocop_todo.yml
|
2
|
+
AllCops:
|
3
|
+
TargetRubyVersion: '2.5'
|
4
|
+
DisplayCopNames: true
|
5
|
+
Exclude:
|
6
|
+
- Gemfile
|
7
|
+
- bin/*
|
8
|
+
- config/**/*
|
9
|
+
- config/application.rb
|
10
|
+
- db/**/*
|
11
|
+
- node_modules/**/*
|
12
|
+
- vendor/engines/*/bin/*
|
13
|
+
- vendor/engines/*/config/*
|
14
|
+
- vendor/engines/*/*.gemspec
|
15
|
+
|
16
|
+
Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/ClassLength:
|
20
|
+
Max: 250
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Max: 50
|
24
|
+
Exclude:
|
25
|
+
- lib/tasks/*.rake
|
26
|
+
- spec/lib/tl_lincoln/factories/*
|
27
|
+
|
28
|
+
Metrics/AbcSize:
|
29
|
+
Max: 30
|
30
|
+
|
31
|
+
Layout/EndOfLine:
|
32
|
+
EnforcedStyle: lf
|
33
|
+
|
34
|
+
Metrics/BlockLength:
|
35
|
+
Max: 30
|
36
|
+
Exclude:
|
37
|
+
- spec/**/*
|
38
|
+
- lib/tasks/*.rake
|
39
|
+
- lib/tl_lincoln/spec/**/*
|
40
|
+
- config/routes.rb
|
41
|
+
- config/environments/*
|
42
|
+
|
43
|
+
Metrics/LineLength:
|
44
|
+
Max: 120
|
45
|
+
|
46
|
+
Metrics/ParameterLists:
|
47
|
+
Max: 10
|
48
|
+
|
49
|
+
Style/AsciiComments:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/BlockComments:
|
53
|
+
Exclude:
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
|
56
|
+
Style/FrozenStringLiteralComment:
|
57
|
+
Exclude:
|
58
|
+
- !ruby/regexp /.xml.builder$/
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,16 +27,19 @@ First of all you need an api_key which you can get at [https://developers.ria.co
|
|
27
27
|
@client = AutoRiaApi::Base.new(api_key: ENV['AUTO_RIA_API_KEY'])
|
28
28
|
|
29
29
|
# Methods:
|
30
|
-
@
|
31
|
-
@
|
32
|
-
@
|
33
|
-
@
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
30
|
+
@client.types
|
31
|
+
@client.carcasses(type:, options: { grouped: false, all: false })
|
32
|
+
@client.marks(type:)
|
33
|
+
@client.models(type:, mark, options: { grouped: false, all: false })
|
34
|
+
@client.regions
|
35
|
+
@client.cities(region:)
|
36
|
+
@client.gearboxes(type:)
|
37
|
+
@client.driver_types(type:)
|
38
|
+
@client.fuels
|
39
|
+
@client.colors
|
40
|
+
@client.options(type:)
|
41
|
+
|
42
|
+
@client.info(car_id:)
|
40
43
|
# all method arguments assuming ID (Integer)
|
41
44
|
|
42
45
|
```
|
@@ -59,7 +62,7 @@ Help is appreciated Feel free to fork and make a difference!
|
|
59
62
|
|
60
63
|
## Tests
|
61
64
|
|
62
|
-
|
65
|
+
run `rspec`
|
63
66
|
|
64
67
|
## License
|
65
68
|
|
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
|
-
def marks(
|
25
|
-
raise ArgumentError, '
|
26
|
-
|
31
|
+
def marks(type:)
|
32
|
+
raise ArgumentError, '`type` should not be empty' if blank?(type)
|
33
|
+
|
34
|
+
request "/auto/categories/#{type}/marks"
|
27
35
|
end
|
28
36
|
|
29
|
-
def models(
|
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,21 @@ 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
|
-
def gearboxes(
|
47
|
-
raise ArgumentError, '
|
48
|
-
|
56
|
+
def gearboxes(type:)
|
57
|
+
raise ArgumentError, '`type` should not be empty' if blank?(type)
|
58
|
+
|
59
|
+
request "/auto/categories/#{type}/gearboxes"
|
49
60
|
end
|
50
61
|
|
51
|
-
def driver_types
|
52
|
-
raise '
|
62
|
+
def driver_types(type:)
|
63
|
+
raise ArgumentError, '`type` should not be empty' if blank?(type)
|
64
|
+
|
65
|
+
request "/auto/categories/#{type}/driverTypes"
|
53
66
|
end
|
54
67
|
|
55
68
|
def fuels
|
@@ -60,39 +73,47 @@ module AutoRiaApi
|
|
60
73
|
request '/auto/colors'
|
61
74
|
end
|
62
75
|
|
63
|
-
def options(
|
64
|
-
raise ArgumentError, '
|
65
|
-
|
76
|
+
def options(type:)
|
77
|
+
raise ArgumentError, '`type` should not be empty' if blank?(type)
|
78
|
+
|
79
|
+
request "/auto/categories/#{type}/auto_options"
|
66
80
|
end
|
67
81
|
|
68
|
-
def average_price(
|
69
|
-
|
82
|
+
def average_price(params)
|
83
|
+
request "/auto/average_price", params
|
70
84
|
end
|
71
85
|
|
72
86
|
def search(*args)
|
73
|
-
raise
|
87
|
+
raise NotImplementedError
|
74
88
|
end
|
75
89
|
|
76
90
|
def info(car_id:)
|
77
|
-
raise ArgumentError, 'car_id should not be empty
|
91
|
+
raise ArgumentError, '`car_id` should not be empty' if blank?(car_id)
|
92
|
+
|
78
93
|
request '/auto/info', auto_id: car_id
|
79
94
|
end
|
80
95
|
|
96
|
+
def photos(car_id:)
|
97
|
+
raise ArgumentError, '`car_id` should not be empty' if blank?(car_id)
|
98
|
+
|
99
|
+
request "/auto/fotos/#{car_id}", auto_id: car_id
|
100
|
+
end
|
101
|
+
|
81
102
|
private
|
82
103
|
|
83
104
|
def request(url, params = {}, method = :get_response)
|
84
|
-
uri = URI(
|
85
|
-
uri.query = URI.encode_www_form(params.merge(api_key:
|
105
|
+
uri = URI(default_url + url)
|
106
|
+
uri.query = URI.encode_www_form(params.merge(api_key: api_key))
|
86
107
|
response = Net::HTTP.public_send(method, uri)
|
87
108
|
parsed response
|
88
109
|
end
|
89
110
|
|
90
111
|
def parsed(response)
|
91
112
|
res = JSON.parse(response.body)
|
113
|
+
raise ResponseError, res.dig('error').to_s if res.is_a?(Hash) && res.has_key?('error')
|
114
|
+
|
92
115
|
yield res if block_given?
|
93
116
|
res
|
94
|
-
rescue => e
|
95
|
-
e
|
96
117
|
end
|
97
118
|
|
98
119
|
def blank?(arg)
|
@@ -100,5 +121,5 @@ module AutoRiaApi
|
|
100
121
|
end
|
101
122
|
end
|
102
123
|
|
103
|
-
class
|
124
|
+
class ResponseError < StandardError; end
|
104
125
|
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.6
|
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-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".rubocop.yml"
|
64
65
|
- ".travis.yml"
|
65
66
|
- Gemfile
|
66
67
|
- Gemfile.lock
|