gillbus 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +10 -0
  5. data/Guardfile +29 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +140 -0
  8. data/Rakefile +9 -0
  9. data/gillbus.gemspec +31 -0
  10. data/lib/gillbus/base_request.rb +99 -0
  11. data/lib/gillbus/base_response.rb +43 -0
  12. data/lib/gillbus/buy_booking.rb +74 -0
  13. data/lib/gillbus/buy_tickets.rb +36 -0
  14. data/lib/gillbus/cancel_order.rb +55 -0
  15. data/lib/gillbus/drivers/faraday_response_file_logger.rb +19 -0
  16. data/lib/gillbus/find_order.rb +37 -0
  17. data/lib/gillbus/get_all_cities.rb +24 -0
  18. data/lib/gillbus/get_cities.rb +34 -0
  19. data/lib/gillbus/get_countries.rb +24 -0
  20. data/lib/gillbus/get_dates_new.rb +35 -0
  21. data/lib/gillbus/get_order_status.rb +28 -0
  22. data/lib/gillbus/get_order_ticket.rb +62 -0
  23. data/lib/gillbus/get_required_fields.rb +32 -0
  24. data/lib/gillbus/get_time_table.rb +33 -0
  25. data/lib/gillbus/get_trip_seats.rb +61 -0
  26. data/lib/gillbus/get_trips.rb +13 -0
  27. data/lib/gillbus/helpers/fields.rb +47 -0
  28. data/lib/gillbus/helpers/parser.rb +100 -0
  29. data/lib/gillbus/helpers/update_attrs.rb +15 -0
  30. data/lib/gillbus/lock_seats.rb +82 -0
  31. data/lib/gillbus/logout.rb +19 -0
  32. data/lib/gillbus/parse_error.rb +11 -0
  33. data/lib/gillbus/reserve_tickets.rb +13 -0
  34. data/lib/gillbus/search_trips.rb +96 -0
  35. data/lib/gillbus/session_login.rb +32 -0
  36. data/lib/gillbus/structs/commission.rb +54 -0
  37. data/lib/gillbus/structs/item.rb +14 -0
  38. data/lib/gillbus/structs/passenger_discount.rb +37 -0
  39. data/lib/gillbus/structs/point.rb +38 -0
  40. data/lib/gillbus/structs/return_cause.rb +23 -0
  41. data/lib/gillbus/structs/seat.rb +38 -0
  42. data/lib/gillbus/structs/segment.rb +161 -0
  43. data/lib/gillbus/structs/tariff.rb +59 -0
  44. data/lib/gillbus/structs/ticket.rb +285 -0
  45. data/lib/gillbus/structs/timetable_segment.rb +51 -0
  46. data/lib/gillbus/structs/timetable_trip.rb +77 -0
  47. data/lib/gillbus/structs/trip.rb +164 -0
  48. data/lib/gillbus/tickets_booking.rb +182 -0
  49. data/lib/gillbus/unlock_seats.rb +15 -0
  50. data/lib/gillbus/version.rb +3 -0
  51. data/lib/gillbus.rb +86 -0
  52. data/script/example_booking.rb +82 -0
  53. data/script/example_booking_with_segments.rb +90 -0
  54. data/script/example_canceling_booking.rb +67 -0
  55. data/script/example_canceling_reservation.rb +69 -0
  56. data/script/example_reservation.rb +88 -0
  57. data/test/buy_booking_test.rb +32 -0
  58. data/test/buy_tickets_test.rb +12 -0
  59. data/test/cancel_order_test.rb +12 -0
  60. data/test/error_test.rb +31 -0
  61. data/test/find_order_test.rb +24 -0
  62. data/test/get_cities_test.rb +12 -0
  63. data/test/get_countries_test.rb +12 -0
  64. data/test/get_dates_new_test.rb +12 -0
  65. data/test/get_order_ticket_test.rb +12 -0
  66. data/test/get_time_table_test.rb +21 -0
  67. data/test/get_trip_seats_test.rb +40 -0
  68. data/test/lock_seats_test.rb +70 -0
  69. data/test/reserve_tickets_test.rb +22 -0
  70. data/test/responses/buyBooking.xml +9 -0
  71. data/test/responses/buyTickets.xml +7 -0
  72. data/test/responses/cancelOrder.xml +8 -0
  73. data/test/responses/error.xml +1 -0
  74. data/test/responses/findOrder.xml +296 -0
  75. data/test/responses/getCities.xml +266 -0
  76. data/test/responses/getCountries.xml +90 -0
  77. data/test/responses/getOrderTicket.xml +3 -0
  78. data/test/responses/getTimeTable.xml +81 -0
  79. data/test/responses/getTripSeats-one-empty-segment.xml +562 -0
  80. data/test/responses/getTripSeats-segments.xml +1052 -0
  81. data/test/responses/getTripSeats.xml +492 -0
  82. data/test/responses/lockSeats.xml +23 -0
  83. data/test/responses/reserveTickets.xml +76 -0
  84. data/test/responses/searchTrips-empty.xml +3 -0
  85. data/test/responses/searchTrips-prod.xml +193 -0
  86. data/test/responses/searchTrips-segments-roundtrip.xml +15812 -0
  87. data/test/responses/searchTrips-segments.xml +808 -0
  88. data/test/responses/sessionLogin.xml +3 -0
  89. data/test/responses/ticketsBooking.xml +75 -0
  90. data/test/responses/very_empty.xml +1 -0
  91. data/test/search_trips_test.rb +71 -0
  92. data/test/session_login_test.rb +12 -0
  93. data/test/test_helper.rb +3 -0
  94. data/test/tickets_booking_test.rb +16 -0
  95. metadata +303 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: abd154225fa9cf95e090acd4e225b7793933afe3
4
+ data.tar.gz: df33244cd12c9948e297301164d27ab7a8c6eb50
5
+ SHA512:
6
+ metadata.gz: 2faa23383a71fe67e11161f9a60b758a8c1020fcf64e0f046c1b2a882eac85ee306d3d46ef72126268a54c79264a621a4a2071bde00119cf07f638ad4fea0e0c
7
+ data.tar.gz: 0b8b35d7b404a02e9ee6ebcdcf9dbc4c97383c07f3b05cbef6ef5ddfd3fc572d2f3ca53aa2ad626d416cda1347144ac647678fdcbb95d3e91fb829c79b879121
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.4
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gillbus.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'guard', github: 'guard/guard'
8
+ gem 'guard-minitest', github: 'guard/guard-minitest'
9
+ gem 'ox'
10
+ end
data/Guardfile ADDED
@@ -0,0 +1,29 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ # with Minitest::Unit
6
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
7
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
8
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
9
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
10
+
11
+ # with Minitest::Spec
12
+ # watch(%r{^spec/(.*)_spec\.rb$})
13
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
14
+ # watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
15
+
16
+ # Rails 4
17
+ # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
18
+ # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
19
+ # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
20
+ # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
21
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
22
+ # watch(%r{^test/.+_test\.rb$})
23
+ # watch(%r{^test/test_helper\.rb$}) { 'test' }
24
+
25
+ # Rails < 4
26
+ # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
27
+ # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
28
+ # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
29
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) BUSFOR LLC (2014-2016)
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # Gillbus
2
+
3
+ Gillbus IDS "online2" API wrapper
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gillbus'
10
+
11
+ ## Public API
12
+
13
+ We're trying hard not to raise exceptions.
14
+ Each call to Gillbus instance returns response object, which responds to #error?
15
+ if #error? is true, you can use #error_message and #error_code
16
+ for exact details
17
+
18
+ ## Workflow
19
+
20
+ * login (sessionLogin/online)
21
+ * /online2/getCountries
22
+ * /online2/getCities
23
+ * /online2/searchTrips
24
+ * /online2/getTrips
25
+ * /online2/getTripSeats
26
+ * /online2/lockSeats
27
+ * /online2/ticketsBooking
28
+ * /online2/buyTickets
29
+ * /online2/getOrderTicket
30
+ * /online2/logout
31
+
32
+ ## Quoting API documentation
33
+
34
+ * Entering the system
35
+ /online2/login/online/
36
+ User authorization
37
+ skipped as obsolete
38
+
39
+ * Entering the system (second way)
40
+ online2/sessionLogin/online/
41
+ User authorization
42
+
43
+ * Get trips’ schedule
44
+ /online2/getTimeTable
45
+ Returns trips schedule
46
+
47
+ * Get country list
48
+ /online2/getCountries
49
+ Returns available countries’ list
50
+
51
+ * Get available localities’ list
52
+ /online2/getCities
53
+ Returns available localities’ list
54
+
55
+ * Get available departure dates’ list
56
+ /online2/getDates
57
+ Returns available departure dates’ list
58
+
59
+ * Get parameterized trips’ list
60
+ /online2/searchTrips
61
+ Returns parameterized trips’ list
62
+
63
+ * Get trips’ list
64
+ /online2/getTrips
65
+ Returns trips’ list
66
+
67
+ * Get seats' map
68
+ /online2/getTripSeats
69
+ Returns seats' map of the vehicle
70
+
71
+ * Locks seats for sale
72
+ /online2/lockSeats
73
+ Locks seats for sale
74
+
75
+ * Unlocks seats for sale
76
+ /online2/unlockSeats
77
+ Unlocks seats for sale
78
+
79
+ * Postponed (unconfirmed) tickets sale
80
+ /online2/bookTickets
81
+ Performs the postponed tickets sale, that waits for the confirmation
82
+
83
+ * Postponed tickets sale (second way)
84
+ /online2/ticketsBooking
85
+ Performs the postponed tickets sale, that waits for the confirmation
86
+
87
+ * Sale confirmation
88
+ /online2/buyTickets
89
+ Confirms the earlier postponed tickets sale
90
+
91
+ * Get the ticket of the order
92
+ /online2/getOrderTicket
93
+ Generates the ticket of the order
94
+
95
+ * Reserve the ticket
96
+ /online2/reserveTickets
97
+ Makes the ticket reservation
98
+
99
+ * Reserved tickets’ search
100
+ /online2/findBooking
101
+ Performs parameterized reserved tickets' search
102
+
103
+ * "Reserved tickets’ search (second way)"
104
+ /online2/findReservation
105
+ Performs parameterized reserved tickets' search
106
+
107
+ * Buyout the reserved ticket
108
+ /online2/buyBooking
109
+ Buyout the earlier reserved ticket
110
+
111
+ * #cancel_order Order cancellation
112
+ /online2/cancelOrder
113
+ Cancels the order
114
+
115
+
116
+ * Returns the item, that had been sold
117
+ /online2/returnPosition
118
+ Returns the item, that had been previously sold
119
+
120
+ * Orders’ search
121
+ /online2/findOrder
122
+ Returns found order's data
123
+
124
+ * Logout
125
+ /online2/logout
126
+ Closes current session
127
+
128
+ * Reporting
129
+ /online2/getReport
130
+ Outputs the reports in the Microsoft Excel format
131
+
132
+ * Get the trips’ list for the date changing
133
+ /online2/getTripsForChange
134
+ Returns the list of trips that are like the assigned trip which has booked ticket, but for the different date.
135
+
136
+ * Departure date change
137
+ /online2/changeTripDate
138
+ Changes the departure date for the passenger
139
+
140
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = "test/*_test.rb"
7
+ end
8
+
9
+ task :default => :test
data/gillbus.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gillbus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gillbus"
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}
12
+ # spec.description = %q{gillbus.com}
13
+ spec.homepage = "http://gillbus.com/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'multi_xml'
22
+ spec.add_dependency 'faraday'
23
+ spec.add_dependency 'money'
24
+ spec.add_dependency 'monetize'
25
+ spec.add_dependency 'activesupport'
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"
31
+ end
@@ -0,0 +1,99 @@
1
+ require 'date'
2
+
3
+ class Gillbus
4
+ class BaseRequest
5
+
6
+ def initialize(attrs={})
7
+ attrs.each do |k, v|
8
+ send "#{k}=", v
9
+ end
10
+ end
11
+
12
+ def path
13
+ raise NotImplementedError, 'you need to define "path" method'
14
+ end
15
+
16
+ def params
17
+ {}
18
+ end
19
+
20
+ private
21
+
22
+ def list(items)
23
+ return if items.nil?
24
+ Array(items).join(";")
25
+ end
26
+
27
+ def date(date)
28
+ return if date.nil?
29
+ date.strftime("%d.%m.%Y")
30
+ end
31
+
32
+ def bool(bool)
33
+ return if bool.nil?
34
+ bool ? "1" : "0"
35
+ end
36
+
37
+ def translated_locale(locale)
38
+ return if locale.nil?
39
+ {
40
+ "ru" => "rus",
41
+ "en" => "lat",
42
+ "uk" => "ukr",
43
+ "th" => "tai",
44
+ "pl" => "pol",
45
+
46
+ # temporary, until changed in busfor
47
+ "ua" => "ukr",
48
+ }[ locale.to_s ] || locale.to_s
49
+ end
50
+
51
+ MODES = {
52
+ # 0 – искать все виды транспорта;
53
+ all: 0,
54
+ # 1 – искать автобусные рейсы;
55
+ bus: 1,
56
+ # 2 - искать такси (только searchTransfersTrips?)
57
+ taxi: 2,
58
+ # 3 – искать авиационные рейсы;
59
+ avia: 3,
60
+ # 4 – искать авиационные чартерные рейсы;
61
+ charter: 4,
62
+ # 6 – рейсы водного транспорта;
63
+ boat: 6,
64
+ # 31 – искать авиационные рейсы эконом-класса;
65
+ avia_economy: 31,
66
+ # 32 – искать авиационные рейсы бизнес-класса;
67
+ avia_business: 32,
68
+ # 51 – искать железнодорожные рейсы;
69
+ train: 51,
70
+ # 8 – искать рейсы с пересадками;
71
+ connections: 8,
72
+ # 9 – искать рейсы только с пересадками.
73
+ connections_only: 9,
74
+ # 13 - автобусно-лодочный микс
75
+ bus_boat: 13,
76
+ }
77
+
78
+ def modes(items)
79
+ list(
80
+ Array(items).map { |item|
81
+ if item.is_a? Symbol
82
+ MODES[item] or
83
+ fail ArgumentError, "unknown search mode #{item.inspect}", caller
84
+ else
85
+ item
86
+ end
87
+ }
88
+ )
89
+ end
90
+
91
+ def compact(hash)
92
+ hash.each do |k,v|
93
+ hash.delete k if v.nil?
94
+ end
95
+ hash
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,43 @@
1
+ require 'multi_xml'
2
+
3
+ class Gillbus
4
+ class BaseResponse
5
+
6
+ extend Fields
7
+ include UpdateAttrs
8
+
9
+ attr_accessor :data
10
+ attr_accessor :session_id
11
+
12
+ attr_accessor :error_code
13
+ attr_accessor :error_message
14
+
15
+ def error?
16
+ ! error_code.nil?
17
+ end
18
+
19
+ def self.parse(data, instance=new)
20
+ # ugly
21
+ if data["MESSAGE"]
22
+ instance.error_code = data["MESSAGE"]["CODE"].to_i
23
+ instance.error_message = data["MESSAGE"]["TEXT"]
24
+ else
25
+ super(data, instance)
26
+ end
27
+ # for debugging?
28
+ instance.data = data
29
+ instance
30
+ end
31
+
32
+ def self.parse_string(xml_string)
33
+ xml = MultiXml.parse(xml_string)
34
+ # <DATA/> is a valid response
35
+ xml.key?("DATA") or return ParseError.new(xml_string)
36
+ data = xml["DATA"] || {}
37
+ parse(data)
38
+ rescue MultiXml::ParseError
39
+ ParseError.new(xml_string)
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,74 @@
1
+ class Gillbus
2
+ module BuyBooking
3
+
4
+ Gillbus.register self, :buy_booking
5
+
6
+ class Request < BaseRequest
7
+
8
+ def path; '/online2/buyBooking' end
9
+
10
+ # paymentMethod (не обязательный)
11
+ # Способ оплаты заказа.
12
+ attr_accessor :payment_method
13
+
14
+ # 1 – наличный;
15
+ METHOD_CASH = 1
16
+ # 2 – кредитной карточкой;
17
+ METHOD_CARD = 2
18
+ # 3 – безналичный;
19
+ METHOD_NOCASH = 3
20
+ # 4 – сервисный;
21
+ METHOD_SERVICE = 4
22
+ # 5 – эквайринг.
23
+ METHOD_ACQUIRING = 5
24
+ # По умолчанию 3.
25
+
26
+ # ticketCount
27
+ # Кол-во выкупаемых билетов. 1..k
28
+ attr_accessor :ticket_count
29
+
30
+ # Номера билетов с порядковым номером
31
+ attr_accessor :ticket_numbers
32
+
33
+ attr_accessor :order_ids
34
+
35
+ def params
36
+ numbers = ticket_numbers.map.with_index do |num, i|
37
+ [:"ticketNumber#{i}", num]
38
+ end.to_h
39
+
40
+ orders = order_ids.map.with_index do |val, i|
41
+ [:"orderId#{i}", val]
42
+ end.to_h
43
+
44
+ compact(
45
+ paymentMethod: payment_method,
46
+ ticketCount: ticket_count,
47
+ **numbers,
48
+ **orders
49
+ )
50
+ end
51
+
52
+ end
53
+
54
+ class Response < BaseResponse
55
+
56
+ class TicketConfirmation
57
+
58
+ extend Fields
59
+
60
+ field :number, :int
61
+ # String. пока не выяснится, в какой таймзоне это значение и зачем
62
+ field :date
63
+ field :order_id
64
+ field :confirmation, :yesno_bool
65
+ field :position_numbers, [:int], key: 'POSITION_NUMBER'
66
+
67
+ end
68
+
69
+ field :ticket, TicketConfirmation
70
+
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,36 @@
1
+ class Gillbus
2
+ module BuyTickets
3
+
4
+ Gillbus.register self, :buy_tickets
5
+
6
+ class Request < BaseRequest
7
+
8
+ def path; '/online2/buyTickets' end
9
+
10
+ # orderId
11
+ # Уникальный ИД заказа, переданный при отложенной продаже.
12
+ attr_accessor :order_id
13
+
14
+ def params
15
+ {orderId: order_id}
16
+ end
17
+ end
18
+
19
+ class Response < BaseResponse
20
+
21
+ class TicketConfirmation
22
+
23
+ extend Fields
24
+ # String. пока не выяснится, в какой таймзоне это значение и зачем
25
+ field :date
26
+ field :order_id
27
+ field :confirmation, :yesno_bool
28
+
29
+ end
30
+
31
+ field :ticket, TicketConfirmation
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,55 @@
1
+ class Gillbus
2
+ module CancelOrder
3
+
4
+ Gillbus.register self, :cancel_order
5
+
6
+ class Request < BaseRequest
7
+
8
+ def path; '/online2/cancelOrder' end
9
+
10
+ # orderNumber
11
+ # The order number
12
+ attr_accessor :order_number
13
+
14
+ # cancelReason
15
+ # Cancellation reason
16
+ attr_accessor :cancel_reason
17
+
18
+ def params
19
+ compact(
20
+ orderNumber: order_number,
21
+ cancelReason: cancel_reason,
22
+ )
23
+ end
24
+
25
+ end
26
+
27
+
28
+ class Response < BaseResponse
29
+
30
+ class OrderCancel
31
+
32
+ extend Fields
33
+
34
+ # The order number
35
+ field :number
36
+
37
+ # The cancellation reason
38
+ field :reason
39
+
40
+ # The flag, which indicates successful order cancellation.
41
+ field :confirmation, :yesno_bool
42
+
43
+ # The request’s performing date
44
+ # String. FIXME (Kiiv timezone?)
45
+ field :date
46
+
47
+ end
48
+
49
+ field :order_cancel, OrderCancel
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,19 @@
1
+ class Gillbus
2
+ class FaradayResponseFileLogger < Faraday::Middleware
3
+
4
+ def initialize(app, dir = '.')
5
+ @dir = dir
6
+ super(app)
7
+ end
8
+
9
+ def call(env)
10
+ path = env.url.path
11
+ @app.call(env).on_complete do |environment|
12
+ sanitized_path = path.gsub(/[^A-Za-z0-9_-]+/, '_').gsub(/^_|_$/, '')
13
+ sanitized_path = '_' if sanitized_path == ''
14
+ File.write(@dir + '/' + sanitized_path, env.body) if env.body != ''
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ class Gillbus
2
+ module FindOrder
3
+
4
+ Gillbus.register self, :find_order
5
+
6
+ class Request < BaseRequest
7
+
8
+ def path; '/online2/findOrder' end
9
+
10
+ # orderId
11
+ # Уникальный ИД заказа, переданный при отложенной продаже.
12
+ attr_accessor :order_id
13
+
14
+ # orderNumber
15
+ # Номер заказа полученный при создании отложенной продажи.
16
+ attr_accessor :order_number
17
+
18
+ # Язык формирования данных.
19
+ attr_accessor :locale
20
+
21
+ def params
22
+ compact(
23
+ orderId: order_id,
24
+ orderNumber: order_number,
25
+ locale: translated_locale(locale),
26
+ )
27
+ end
28
+
29
+ end
30
+
31
+ class Response < BaseResponse
32
+ field :tickets, [Ticket], key: 'TICKET'
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,24 @@
1
+ class Gillbus
2
+ module GetAllCities
3
+
4
+ Gillbus.register self, :get_all_cities
5
+
6
+ class Request < BaseRequest
7
+ def path; '/online2/getAllCities' end
8
+ end
9
+
10
+ class City
11
+ extend Fields
12
+ include UpdateAttrs
13
+ field :id
14
+ field :name
15
+ field :country_id
16
+ field :country_name
17
+ end
18
+
19
+ class Response < BaseResponse
20
+ field :cities, [City], key: 'CITY'
21
+ end
22
+
23
+ end
24
+ end