gillbus 0.16.7 → 0.16.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +88 -0
  3. data/Rakefile +3 -3
  4. data/gillbus.gemspec +16 -15
  5. data/lib/gillbus.rb +10 -9
  6. data/lib/gillbus/base_request.rb +17 -19
  7. data/lib/gillbus/base_response.rb +11 -13
  8. data/lib/gillbus/buy_booking.rb +1 -9
  9. data/lib/gillbus/buy_tickets.rb +1 -8
  10. data/lib/gillbus/cancel_order.rb +0 -10
  11. data/lib/gillbus/drivers/faraday_response_file_logger.rb +1 -3
  12. data/lib/gillbus/find_order.rb +0 -5
  13. data/lib/gillbus/get_all_cities.rb +0 -2
  14. data/lib/gillbus/get_bus_image.rb +0 -3
  15. data/lib/gillbus/get_cities.rb +0 -4
  16. data/lib/gillbus/get_countries.rb +0 -4
  17. data/lib/gillbus/get_dates_new.rb +0 -4
  18. data/lib/gillbus/get_order_status.rb +1 -6
  19. data/lib/gillbus/get_order_ticket.rb +4 -7
  20. data/lib/gillbus/get_time_table.rb +0 -4
  21. data/lib/gillbus/get_trip_seats.rb +8 -11
  22. data/lib/gillbus/get_trip_segments.rb +0 -2
  23. data/lib/gillbus/get_trips.rb +0 -2
  24. data/lib/gillbus/helpers/fields.rb +5 -7
  25. data/lib/gillbus/helpers/parser.rb +10 -13
  26. data/lib/gillbus/helpers/update_attrs.rb +2 -4
  27. data/lib/gillbus/lock_seats.rb +7 -10
  28. data/lib/gillbus/logout.rb +0 -6
  29. data/lib/gillbus/parse_error.rb +3 -1
  30. data/lib/gillbus/reserve_tickets.rb +0 -2
  31. data/lib/gillbus/return_position.rb +0 -1
  32. data/lib/gillbus/search_trips.rb +5 -6
  33. data/lib/gillbus/session_login.rb +0 -6
  34. data/lib/gillbus/structs/commission.rb +4 -4
  35. data/lib/gillbus/structs/item.rb +0 -2
  36. data/lib/gillbus/structs/passenger_discount.rb +2 -3
  37. data/lib/gillbus/structs/point.rb +0 -1
  38. data/lib/gillbus/structs/return_cause.rb +0 -2
  39. data/lib/gillbus/structs/seat.rb +0 -2
  40. data/lib/gillbus/structs/segment.rb +5 -6
  41. data/lib/gillbus/structs/tariff.rb +1 -2
  42. data/lib/gillbus/structs/tariff/return_cause.rb +3 -3
  43. data/lib/gillbus/structs/ticket.rb +0 -2
  44. data/lib/gillbus/structs/timetable_trip.rb +4 -4
  45. data/lib/gillbus/structs/trip.rb +5 -6
  46. data/lib/gillbus/structs/trip_options.rb +0 -1
  47. data/lib/gillbus/structs/trip_service.rb +0 -2
  48. data/lib/gillbus/tickets_booking.rb +17 -13
  49. data/lib/gillbus/unlock_seats.rb +0 -2
  50. data/lib/gillbus/version.rb +1 -1
  51. data/script/example_booking.rb +16 -18
  52. data/script/example_booking_with_segments.rb +0 -1
  53. data/script/example_canceling_booking.rb +12 -13
  54. data/script/example_canceling_reservation.rb +11 -12
  55. data/script/example_reservation.rb +14 -15
  56. data/test/all_commissions_test.rb +1 -2
  57. data/test/buy_booking_test.rb +14 -13
  58. data/test/buy_tickets_test.rb +1 -2
  59. data/test/cancel_order_test.rb +1 -2
  60. data/test/error_test.rb +1 -3
  61. data/test/find_order_test.rb +3 -4
  62. data/test/get_bus_image_test.rb +0 -1
  63. data/test/get_cities_test.rb +1 -2
  64. data/test/get_countries_test.rb +1 -2
  65. data/test/get_dates_new_test.rb +0 -1
  66. data/test/get_order_ticket_test.rb +1 -2
  67. data/test/get_time_table_test.rb +0 -1
  68. data/test/get_trip_seats_test.rb +3 -4
  69. data/test/get_trip_segments_test.rb +5 -6
  70. data/test/lock_seats_test.rb +43 -33
  71. data/test/reserve_tickets_test.rb +10 -3
  72. data/test/return_position_test.rb +8 -5
  73. data/test/search_trips_test.rb +15 -19
  74. data/test/session_login_test.rb +0 -1
  75. data/test/tickets_booking_test.rb +2 -3
  76. metadata +24 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfd0ac869d9d605b0344ae93bc7c0f26c8dce47a
4
- data.tar.gz: c625a743ef866ce2cdd2671696afca22b29c396b
3
+ metadata.gz: c31563ca394a9b38057c5aceae871ffdb9dd524c
4
+ data.tar.gz: 5195a899582e383ad2b364beda39cb580cd61f04
5
5
  SHA512:
6
- metadata.gz: 857e79e6e0b3865f781693b3ad69cde047afacb98a344b2419348f25facfe3fd1ed3898012de843688c6ab2281bacdce2aa2da489688f6527d1d4eec3b079145
7
- data.tar.gz: f7b1c07c2cef34801f585b497069228c10f144a766d2a2ccc829079cce93fcdfcc07bf89ee85293e3727ae3cdd2afbbd2182ff1a07413e7c09bb39d092521af1
6
+ metadata.gz: d790d9c12625b44300dc4dbb754d0bb69ad5c8ac7257a113baf1d52adebac4905e2bd581bdfc644729d7f29db4d84aeba9de7ce27370cbc83e5116735fc30538
7
+ data.tar.gz: ab80e525e02f95bbacb0bee58fa52e2e7899f6dd827d00fcb5cd2ca7d6c84a7fd2deded4d5c2866ed5647ffb51779190e460cd646878a423f1e82b900eb1e2e9
@@ -0,0 +1,88 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ DisplayCopNames: true
4
+ DisplayStyleGuide: true
5
+ Exclude:
6
+ - 'script/*'
7
+
8
+ Metrics/LineLength:
9
+ Max: 120
10
+
11
+ Metrics/ClassLength:
12
+ Max: 125
13
+
14
+ Metrics/MethodLength:
15
+ Max: 20
16
+ Exclude:
17
+ - 'test/*'
18
+
19
+ Style/DateTime:
20
+ Exclude:
21
+ - 'test/*'
22
+
23
+ Style/ZeroLengthPredicate:
24
+ Exclude:
25
+ - 'test/*'
26
+
27
+ Style/TrailingCommaInLiteral:
28
+ EnforcedStyleForMultiline: comma
29
+
30
+ Style/TrailingCommaInArguments:
31
+ EnforcedStyleForMultiline: comma
32
+
33
+ Layout/AlignParameters:
34
+ EnforcedStyle: with_fixed_indentation
35
+
36
+ Layout/MultilineMethodCallBraceLayout:
37
+ EnforcedStyle: new_line
38
+
39
+ Layout/MultilineMethodCallIndentation:
40
+ EnforcedStyle: indented
41
+
42
+ Layout/IndentHash:
43
+ EnforcedStyle: consistent
44
+
45
+ Style/AsciiComments:
46
+ Enabled: false
47
+
48
+ Style/Documentation:
49
+ Enabled: false
50
+
51
+ Style/ClassAndModuleChildren:
52
+ Enabled: false
53
+
54
+ Style/FrozenStringLiteralComment:
55
+ Enabled: false
56
+
57
+ Style/SingleLineMethods:
58
+ Enabled: false
59
+
60
+ Style/NumericLiterals:
61
+ Enabled: false
62
+
63
+ Style/WordArray:
64
+ Enabled: false
65
+
66
+ Style/SymbolArray:
67
+ Enabled: false
68
+
69
+ Style/NumericPredicate:
70
+ Enabled: false
71
+
72
+ Style/PerlBackrefs:
73
+ Enabled: false
74
+
75
+ Metrics/AbcSize:
76
+ Enabled: false
77
+
78
+ Metrics/CyclomaticComplexity:
79
+ Enabled: false
80
+
81
+ Metrics/PerceivedComplexity:
82
+ Enabled: false
83
+
84
+ Naming/AccessorMethodName:
85
+ Enabled: false
86
+
87
+ Lint/CircularArgumentReference:
88
+ Enabled: false
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'test'
6
- t.pattern = "test/*_test.rb"
6
+ t.pattern = 'test/*_test.rb'
7
7
  t.warning = false
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -1,31 +1,32 @@
1
- # coding: utf-8
1
+
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'gillbus/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "gillbus"
7
+ spec.name = 'gillbus'
8
8
  spec.version = Gillbus::VERSION
9
- spec.authors = [%q{Alexey "codesnik" Trofimenko}, %q{Kirill Platonov}]
10
- spec.email = ["aronaxis@gmail.com", "mail@kirillplatonov.com"]
11
- spec.summary = %q{Driver for Gillbus IDS API}
9
+ spec.authors = ['Alexey "codesnik" Trofimenko', 'Kirill Platonov']
10
+ spec.email = ['aronaxis@gmail.com', 'mail@kirillplatonov.com']
11
+ spec.summary = 'Driver for Gillbus IDS API'
12
12
  # spec.description = %q{gillbus.com}
13
- spec.homepage = "http://gillbus.com/"
14
- spec.license = "MIT"
13
+ spec.homepage = 'http://gillbus.com/'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'multi_xml'
21
+ spec.add_dependency 'activesupport'
22
22
  spec.add_dependency 'faraday'
23
- spec.add_dependency 'money'
24
23
  spec.add_dependency 'monetize'
25
- spec.add_dependency 'activesupport'
24
+ spec.add_dependency 'money'
25
+ spec.add_dependency 'multi_xml'
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.6"
28
- spec.add_development_dependency "rake"
29
- spec.add_development_dependency "minitest"
30
- spec.add_development_dependency "pry"
27
+ spec.add_development_dependency 'bundler', '~> 1.6'
28
+ spec.add_development_dependency 'minitest'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rubocop', '~> 0.51.0'
31
32
  end
@@ -1,12 +1,12 @@
1
- require "gillbus/version"
2
- require "faraday"
1
+ require 'gillbus/version'
2
+ require 'faraday'
3
3
 
4
4
  class Gillbus
5
-
6
5
  # driver: e.g. Faraday.new(url: 'http://demo.gillbus.com')
7
- def initialize(driver:, session_id: nil)
6
+ def initialize(driver:, session_id: nil, timezone: nil)
8
7
  @driver = driver
9
8
  @session_id = session_id
9
+ @timezone = timezone
10
10
  end
11
11
 
12
12
  # Faraday instance
@@ -19,17 +19,18 @@ class Gillbus
19
19
  self
20
20
  end
21
21
 
22
- def self.register klass, method_name
22
+ def self.register(klass, method_name)
23
23
  define_method method_name do |*args|
24
24
  request_class = klass::Request
25
25
  response_class = klass::Response
26
26
  request = request_class.new(*args)
27
- headers = {'Cookie' => "JSESSIONID=#{session_id}"} if session_id
27
+ headers = { 'Cookie' => "JSESSIONID=#{session_id}" } if session_id
28
28
  request_time_start = Time.now
29
- http_response = driver.public_send( request.method, request.path, request.params, headers )
29
+ http_response = driver.public_send(request.method, request.path, request.params, headers)
30
30
  request_time_end = Time.now
31
- result = response_class.parse_string(http_response.body.force_encoding('utf-8'))
32
- if cookie_string = http_response.headers["Set-Cookie"]
31
+ result = response_class.parse_string(http_response.body.force_encoding('utf-8'), timezone: timezone)
32
+ cookie_string = http_response.headers['Set-Cookie']
33
+ if cookie_string
33
34
  returned_session_id = CGI::Cookie.parse(cookie_string)['JSESSIONID'].first
34
35
  self.session_id = returned_session_id
35
36
  end
@@ -2,8 +2,7 @@ require 'date'
2
2
 
3
3
  class Gillbus
4
4
  class BaseRequest
5
-
6
- def initialize(attrs={})
5
+ def initialize(attrs = {})
7
6
  attrs.each do |k, v|
8
7
  send "#{k}=", v
9
8
  end
@@ -25,31 +24,31 @@ class Gillbus
25
24
 
26
25
  def list(items)
27
26
  return if items.nil?
28
- Array(items).join(";")
27
+ Array(items).join(';')
29
28
  end
30
29
 
31
30
  def date(date)
32
31
  return if date.nil?
33
- date.strftime("%d.%m.%Y")
32
+ date.strftime('%d.%m.%Y')
34
33
  end
35
34
 
36
35
  def bool(bool)
37
36
  return if bool.nil?
38
- bool ? "1" : "0"
37
+ bool ? '1' : '0'
39
38
  end
40
39
 
41
40
  def translated_locale(locale)
42
41
  return if locale.nil?
43
42
  {
44
- "ru" => "rus",
45
- "en" => "lat",
46
- "uk" => "ukr",
47
- "th" => "tai",
48
- "pl" => "pol",
43
+ 'ru' => 'rus',
44
+ 'en' => 'lat',
45
+ 'uk' => 'ukr',
46
+ 'th' => 'tai',
47
+ 'pl' => 'pol',
49
48
 
50
49
  # temporary, until changed in busfor
51
- "ua" => "ukr",
52
- }[ locale.to_s ] || locale.to_s
50
+ 'ua' => 'ukr',
51
+ }[locale.to_s] || locale.to_s
53
52
  end
54
53
 
55
54
  MODES = {
@@ -77,27 +76,26 @@ class Gillbus
77
76
  connections_only: 9,
78
77
  # 13 - автобусно-лодочный микс
79
78
  bus_boat: 13,
80
- }
79
+ }.freeze
81
80
 
82
81
  def modes(items)
83
82
  list(
84
- Array(items).map { |item|
83
+ Array(items).map do |item|
85
84
  if item.is_a? Symbol
86
- MODES[item] or
87
- fail ArgumentError, "unknown search mode #{item.inspect}", caller
85
+ MODES[item] ||
86
+ raise(ArgumentError, "unknown search mode #{item.inspect}", caller)
88
87
  else
89
88
  item
90
89
  end
91
- }
90
+ end,
92
91
  )
93
92
  end
94
93
 
95
94
  def compact(hash)
96
- hash.each do |k,v|
95
+ hash.each do |k, v|
97
96
  hash.delete k if v.nil?
98
97
  end
99
98
  hash
100
99
  end
101
-
102
100
  end
103
101
  end
@@ -2,7 +2,6 @@ require 'multi_xml'
2
2
 
3
3
  class Gillbus
4
4
  class BaseResponse
5
-
6
5
  extend Fields
7
6
  include UpdateAttrs
8
7
 
@@ -15,32 +14,31 @@ class Gillbus
15
14
  attr_accessor :request_time
16
15
 
17
16
  def error?
18
- ! error_code.nil?
17
+ !error_code.nil?
19
18
  end
20
19
 
21
- def self.parse(data, instance=new)
20
+ def self.parse(data, instance: new, options: options)
22
21
  # ugly
23
- if data["MESSAGE"]
24
- instance.error_code = data["MESSAGE"]["CODE"].to_i
25
- instance.error_message = data["MESSAGE"]["TEXT"]
26
- instance.external_error_message = data["MESSAGE"]["EXT_TEXT"]
22
+ if data['MESSAGE']
23
+ instance.error_code = data['MESSAGE']['CODE'].to_i
24
+ instance.error_message = data['MESSAGE']['TEXT']
25
+ instance.external_error_message = data['MESSAGE']['EXT_TEXT']
27
26
  else
28
- super(data, instance)
27
+ super(data, instance: instance, options: options)
29
28
  end
30
29
  # for debugging?
31
30
  instance.data = data
32
31
  instance
33
32
  end
34
33
 
35
- def self.parse_string(xml_string)
34
+ def self.parse_string(xml_string, **options)
36
35
  xml = MultiXml.parse(xml_string)
37
36
  # <DATA/> is a valid response
38
- xml.key?("DATA") or return ParseError.new(xml_string)
39
- data = xml["DATA"] || {}
40
- parse(data)
37
+ return ParseError.new(xml_string) unless xml.key?('DATA')
38
+ data = xml['DATA'] || {}
39
+ parse(data, instance: new, options: options)
41
40
  rescue MultiXml::ParseError, ArgumentError
42
41
  ParseError.new(xml_string)
43
42
  end
44
-
45
43
  end
46
44
  end
@@ -1,10 +1,8 @@
1
1
  class Gillbus
2
2
  module BuyBooking
3
-
4
3
  Gillbus.register self, :buy_booking
5
4
 
6
5
  class Request < BaseRequest
7
-
8
6
  def path; '/online2/buyBooking' end
9
7
 
10
8
  # paymentMethod (не обязательный)
@@ -45,16 +43,13 @@ class Gillbus
45
43
  paymentMethod: payment_method,
46
44
  ticketCount: ticket_count,
47
45
  **numbers,
48
- **orders
46
+ **orders,
49
47
  )
50
48
  end
51
-
52
49
  end
53
50
 
54
51
  class Response < BaseResponse
55
-
56
52
  class TicketConfirmation
57
-
58
53
  extend Fields
59
54
 
60
55
  field :number, :int
@@ -63,12 +58,9 @@ class Gillbus
63
58
  field :order_id
64
59
  field :confirmation, :yesno_bool
65
60
  field :position_numbers, [:int], key: 'POSITION_NUMBER'
66
-
67
61
  end
68
62
 
69
63
  field :ticket, TicketConfirmation
70
-
71
64
  end
72
-
73
65
  end
74
66
  end
@@ -1,10 +1,8 @@
1
1
  class Gillbus
2
2
  module BuyTickets
3
-
4
3
  Gillbus.register self, :buy_tickets
5
4
 
6
5
  class Request < BaseRequest
7
-
8
6
  def path; '/online2/buyTickets' end
9
7
 
10
8
  # orderId
@@ -12,25 +10,20 @@ class Gillbus
12
10
  attr_accessor :order_id
13
11
 
14
12
  def params
15
- {orderId: order_id}
13
+ { orderId: order_id }
16
14
  end
17
15
  end
18
16
 
19
17
  class Response < BaseResponse
20
-
21
18
  class TicketConfirmation
22
-
23
19
  extend Fields
24
20
  # String. пока не выяснится, в какой таймзоне это значение и зачем
25
21
  field :date
26
22
  field :order_id
27
23
  field :confirmation, :yesno_bool
28
-
29
24
  end
30
25
 
31
26
  field :ticket, TicketConfirmation
32
-
33
27
  end
34
-
35
28
  end
36
29
  end
@@ -1,10 +1,8 @@
1
1
  class Gillbus
2
2
  module CancelOrder
3
-
4
3
  Gillbus.register self, :cancel_order
5
4
 
6
5
  class Request < BaseRequest
7
-
8
6
  def path; '/online2/cancelOrder' end
9
7
 
10
8
  # orderNumber
@@ -21,14 +19,10 @@ class Gillbus
21
19
  cancelReason: cancel_reason,
22
20
  )
23
21
  end
24
-
25
22
  end
26
23
 
27
-
28
24
  class Response < BaseResponse
29
-
30
25
  class OrderCancel
31
-
32
26
  extend Fields
33
27
 
34
28
  # The order number
@@ -43,13 +37,9 @@ class Gillbus
43
37
  # The request’s performing date
44
38
  # String. FIXME (Kiiv timezone?)
45
39
  field :date
46
-
47
40
  end
48
41
 
49
42
  field :order_cancel, OrderCancel
50
-
51
43
  end
52
-
53
44
  end
54
-
55
45
  end