auto_ria_api 0.1.1 → 0.1.6

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: 5ad52d92d1b42ebfe2298c8c65d6e1860f88c6ad794fa8fc51dadf2de730422a
4
- data.tar.gz: 92653049945c86cacf4ea14f83de2d6897d7aaf70663f44fb4d4d67dd31fb480
3
+ metadata.gz: a8ab0dcbe23001fb09d111b0ec606aa294c36b3127d12305e34b6e56ff006cf9
4
+ data.tar.gz: 86482a3933c9471daa342de07f7fcb27432beb7888f48f54d8b8657bf3970464
5
5
  SHA512:
6
- metadata.gz: c55d7cda985ce3ec8b7a2086a55ec4ba9c50699f09bed831dc0384f63dcf4ed947306f037ad5b47f5beb13a5708b2f0e475cdd360cbe53eccee7a718d5aab8b5
7
- data.tar.gz: 4037cbeb2ba4f3c93dd2379e149f5f98f4530118d9dd2e5bb4e5d6be5075dd260210110c1102fb929d4b43941e8cc4268c9437d2196f08dce115d4f3a1aa1e8a
6
+ metadata.gz: 5a920fe0b529b321c8afd3579b2b1079c8fa0e20dcd1260a198a82d6de74765bea89e3dc211b03161096356402614847f1902cd4e7d2561217b52b90a4fde0a7
7
+ data.tar.gz: 53ac1564848628d3fbe1749dfa86452ff4a4f0bee6707276ab38bef2623d77fc46c18486bcf46927858c10c71fd2f5ef5e3ad57ddffc4b58a89226901f137cf5
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ # IDE
14
+ .idea/
@@ -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
@@ -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
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- auto_ria_api (0.1.1)
4
+ auto_ria_api (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,4 +32,4 @@ DEPENDENCIES
32
32
  rspec (~> 3.0)
33
33
 
34
34
  BUNDLED WITH
35
- 1.17.1
35
+ 1.17.3
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
- @clien.types
31
- @clien.carcasses(type, grouped: false, all: false)
32
- @clien.marks(carcasse)
33
- @clien.models(carcasse, mark, grouped: false, all: false)
34
- @clien.regions
35
- @clien.cities(region)
36
- @clien.gearboxes(carcasse)
37
- @clien.fuels
38
- @clien.colors
39
- @clien.options(carcasse)
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
- 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`
65
+ run `rspec`
63
66
 
64
67
  ## License
65
68
 
@@ -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
@@ -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
- def marks(carcasse:)
25
- raise ArgumentError, 'Carcass should not be empty.' if blank?(carcasse)
26
- request "/auto/categories/#{carcasse}/marks"
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(carcasse:, mark:, grouped: false, all: false)
30
- raise ArgumentError, 'Carcass should not be empty.' if blank?(carcasse)
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/#{carcasse}/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,21 @@ 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
- def gearboxes(carcasse:)
47
- raise ArgumentError, 'Carcasse should not be empty.' if blank?(carcasse)
48
- request "/auto/categories/#{carcasse}/gearboxes"
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 'Not implemented'
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(carcasse:)
64
- raise ArgumentError, 'Carcasse should not be empty.' if blank?(carcasse)
65
- request "/auto/categories/#{carcasse}/auto_options"
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(*args)
69
- raise 'Not implemented'
82
+ def average_price(params)
83
+ request "/auto/average_price", params
70
84
  end
71
85
 
72
86
  def search(*args)
73
- raise 'Not implemented'
87
+ raise NotImplementedError
74
88
  end
75
89
 
76
90
  def info(car_id:)
77
- raise ArgumentError, 'car_id should not be empty.' if blank?(car_id)
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(@default_url + url)
85
- uri.query = URI.encode_www_form(params.merge(api_key: @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 Error < StandardError; end
124
+ class ResponseError < StandardError; end
104
125
  end
@@ -1,3 +1,3 @@
1
1
  module AutoRiaApi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.6'
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.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: 2018-11-12 00:00:00.000000000 Z
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