mr_speedy_ruby 1.0.0.pre.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2156a454d95152c80a1ad9e229193bde625d4f8f75af06f074cbf7425aa60983
4
+ data.tar.gz: 8c5915a58da4cbb598a99fda9d04b32e3d1900343b540bc6e90b40eafbc2482d
5
+ SHA512:
6
+ metadata.gz: c72899df3891543bb8c36c025f67674b64a52bcdaeb1e65e4ceef354fb43702fc5918348746a626e6dfd98612693a092317f3c458f376729de5d7c5c2c2479e7
7
+ data.tar.gz: '0912f29cdacf1375a72bb48562d651b98adeaa1efd891ab535a2be8cfa0b69be055faf335f039d7b70891e637cfb78c52b056d2099673c485b3bc73bdff44ace'
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.0
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at peterjohn@gorated.ph. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mr_speedy_ruby.gemspec
4
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mr_speedy_ruby (1.0.0.pre.alpha.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ awesome_print (1.8.0)
12
+ coderay (1.1.2)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ hashdiff (1.0.1)
16
+ method_source (1.0.0)
17
+ minitest (5.14.0)
18
+ pry (0.13.1)
19
+ coderay (~> 1.1)
20
+ method_source (~> 1.0)
21
+ public_suffix (4.0.5)
22
+ rake (13.0.1)
23
+ safe_yaml (1.0.5)
24
+ vcr (5.1.0)
25
+ webmock (3.8.3)
26
+ addressable (>= 2.3.6)
27
+ crack (>= 0.3.2)
28
+ hashdiff (>= 0.4.0, < 2.0.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ awesome_print
35
+ bundler (~> 2.0)
36
+ minitest (~> 5.0)
37
+ mr_speedy_ruby!
38
+ pry
39
+ rake (~> 13.0)
40
+ vcr (~> 5.1.0)
41
+ webmock (~> 3.8.3)
42
+
43
+ BUNDLED WITH
44
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Peter John Alvarado
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,164 @@
1
+ # MrSpeedyRuby
2
+ [Mr.Speedy](https://mrspeedy.ph/) Api Integration For Ruby and Ruby On Rails
3
+ ===
4
+
5
+ ![Travis (.org)](https://img.shields.io/travis/redjoker011/mr_speedy_ruby)
6
+ ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/redjoker011/mr_speedy_ruby?include_prereleases)
7
+ ![Gem](https://img.shields.io/gem/v/mr_speedy_ruby)
8
+
9
+ [![GitHub license](https://img.shields.io/github/license/redjoker011/mr_speedy_ruby)](https://github.com/redjoker011/mr_speedy_ruby/blob/development/LICENSE.txt)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'mr_speedy_ruby'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install mr_speedy_ruby
26
+
27
+ ## Usage
28
+ This gem will provide service for integrating mr.speedy in your ruby app with
29
+ ease.
30
+
31
+ ### Initialize Client
32
+ We can initialize mr.speedy api client by providing authentication token
33
+ located in our mr.speedy account setting.
34
+
35
+ ```ruby
36
+ MrSpeedyRuby::Client.new(token: "mr-speedy-token")
37
+ ```
38
+
39
+ ### Calculate Delivey Fee
40
+ Send request to mr.speedy api for delivery fee calculation by providing delivery
41
+ and pickup details
42
+
43
+ ```ruby
44
+ client = MrSpeedyRuby::Client.new(token: "mr-speedy-token")
45
+
46
+ # Pickup Location Details Including Contact Person and Package
47
+ pickup = {
48
+ address: "Capitol Park Homes, 71 Berlin Avenue, Matandang Balara, Quezon City, Metro Manila",
49
+ contact_person: { name: "Admin One", phone: "639123456789" },
50
+ packages: []
51
+ }
52
+
53
+ # Delivery Location Details Including Contact Person and Package
54
+ delivery = {
55
+ address: "Unit 802, EcoTower, 32nd Street corner 9th Avenue, BGC, Taguig, 1634 Metro Manila",
56
+ contact_person: { name: "Admin One", phone: "639123456789" },
57
+ packages: []
58
+ }
59
+
60
+ # Additional Parameters
61
+ options = { matter: "Food" }
62
+
63
+ client.calculate_fees(delivery: delivery, pickup: pickup, opts: options, sandbox: true)
64
+ ```
65
+
66
+ Theres so many things happening here first we initialize our client by providing
67
+ token , then we pass delivery details as separate entity from options so we can
68
+ easily validate required delivery details parameter. We also pass additional
69
+ required parameter `matter` which indicates parcel type and lastly we call
70
+ `MrSpeedyRuby::Client#calculate_fees` to send request for delivery fee
71
+ calculation to mr.speedy api.
72
+
73
+ Also note we pass `sandbox` parameter with true value to indicate that we want
74
+ to make a request on mr.speedy sandbox server.
75
+
76
+ ##### Note:
77
+
78
+ [Order Price Calculation](https://apitest.mrspeedy.ph/business-api/doc#calculate-order) parameters can also be passed as options.
79
+
80
+ [Delivery Details](https://apitest.mrspeedy.ph/business-api/doc#calculate-order) can also be passed along pickup/delivery params.
81
+
82
+ By default we set `MOTORBIKE` as default vehicle unless you pass `vehicle_type_id` as option for `opts`.
83
+
84
+ ### Placing an Order
85
+ Send request to mr.speedy api to create order.
86
+
87
+ ```ruby
88
+ client = MrSpeedyRuby::Client.new(token: "mr-speedy-token")
89
+
90
+ # Pickup Location Details Including Contact Person and Package
91
+ pickup = {
92
+ address: "Capitol Park Homes, 71 Berlin Avenue, Matandang Balara, Quezon City, Metro Manila",
93
+ contact_person: { name: "Admin One", phone: "639277876287" },
94
+ packages: []
95
+ }
96
+
97
+ # Delivery Location Details Including Contact Person and Package
98
+ delivery = {
99
+ address: "Unit 802, EcoTower, 32nd Street corner 9th Avenue, BGC, Taguig, 1634 Metro Manila",
100
+ contact_person: { name: "Admin One", phone: "639277876287" },
101
+ packages: []
102
+ }
103
+
104
+ # Additional Parameters
105
+ options = { matter: "Food" }
106
+
107
+ client.place_order(delivery: delivery, pickup: pickup, opts: options, sandbox: true)
108
+ ```
109
+ Like `delivery fee calculation` we also do the same steps and pass the exact
110
+ parameter to ensure that we have the same `delivery fee`, We also set `sandbox`
111
+ parameter to true to test our implementation against sandbox server.
112
+
113
+ ##### Note:
114
+
115
+ [Order Creation](https://apitest.mrspeedy.ph/business-api/doc#create-order) parameters can also be passed as options.
116
+
117
+ [Delivery Details](https://apitest.mrspeedy.ph/business-api/doc#create-order) can also be passed along pickup/delivery params.
118
+
119
+ By default we set `MOTORBIKE` as default vehicle unless you pass `vehicle_type_id` as option for `opts`.
120
+
121
+ ## Development
122
+
123
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
124
+
125
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
126
+
127
+
128
+ ### Features
129
+
130
+ - [x] Delivery Fee Calculation
131
+ - [x] Create Order
132
+ - [ ] Update Order
133
+ - [ ] Cancel Order
134
+ - [ ] Order List
135
+ - [ ] Courier Info and Location Tracker
136
+ - [ ] Create Draft Deliveries
137
+ - [ ] Update Draft Deliveries
138
+ - [ ] Draft Delivery Deletion
139
+ - [ ] Draft Delivery List
140
+ - [ ] API Setting Update
141
+ - [ ] Request Error Handling
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
146
+
147
+ ## Code of Conduct
148
+
149
+ Everyone interacting in the MrSpeedyRuby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/redjoker011/mr_speedy_ruby/blob/master/CODE_OF_CONDUCT.md).
150
+
151
+ ## Contributing
152
+ Bug reports and pull requests are welcome on GitHub at https://github.com/redjoker011/mr_speedy_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
153
+
154
+ ## Contributors
155
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
156
+
157
+ <table>
158
+ <tr>
159
+ <td align="center"><a href="https://github.com/redjoker011"><img src="https://avatars2.githubusercontent.com/u/22144212?v=4" width="100px;" alt=""/><br /><sub><b>Peter John Alvarado</b></sub></a><br /></td>
160
+ <td align="center"><a href="https://github.com/cjbmartinez"><img src="https://avatars2.githubusercontent.com/u/34258568?v=4" width="100px;" alt=""/><br /><sub><b>Charles Martinez</b></sub></a><br /></td>
161
+ </tr>
162
+ </table>
163
+
164
+ <!-- ALL-CONTRIBUTORS-LIST:END - Do not remove or modify this section -->
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mr_speedy_ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://robotapitest.mrspeedy.ph/api/business/1.1/calculate-order
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"matter":"Food","vehicle_type_id":8,"points":[{"address":"Capitol
9
+ Park Homes, 71 Berlin Avenue, Matandang Balara, Quezon City, Metro Manila","contact_person":{"name":"Merchant","phone":"639123456789"},"packages":[]},{"address":"Unit
10
+ 802, EcoTower, 32nd Street corner 9th Avenue, BGC, Taguig, 1634 Metro Manila","contact_person":{"name":"Reciever","phone":"639123456789"},"packages":[]}]}'
11
+ headers:
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ Host:
19
+ - robotapitest.mrspeedy.ph
20
+ X-Dv-Auth-Token:
21
+ - 70B4ABCA8A35AC50E1585E27F217DF160F740D46
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Server:
28
+ - nginx
29
+ Date:
30
+ - Tue, 12 May 2020 13:22:18 GMT
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Transfer-Encoding:
34
+ - chunked
35
+ Connection:
36
+ - keep-alive
37
+ Vary:
38
+ - Accept-Encoding
39
+ X-Frame-Options:
40
+ - DENY
41
+ X-Content-Type-Options:
42
+ - nosniff
43
+ X-Xss-Protection:
44
+ - 1; mode=block;
45
+ Strict-Transport-Security:
46
+ - max-age=31536000; includeSubDomains
47
+ body:
48
+ encoding: ASCII-8BIT
49
+ string: '{"is_successful":true,"order":{"order_id":null,"order_name":null,"vehicle_type_id":8,"created_datetime":"2020-05-12T21:22:18+08:00","finish_datetime":null,"status":null,"matter":"Food","total_weight_kg":0,"is_client_notification_enabled":false,"is_contact_person_notification_enabled":false,"loaders_count":0,"backpayment_details":null,"points":[{"point_type":"plain","point_id":null,"client_order_id":null,"address":"Zurich
50
+ Ave, Matandang Balara, Quezon City, Metro Manila, Philippines","latitude":"14.6710069","longitude":"121.0944076","required_start_datetime":"2020-05-12T21:22:18+08:00","required_finish_datetime":"2020-05-12T22:30:00+08:00","arrival_start_datetime":null,"arrival_finish_datetime":null,"courier_visit_datetime":null,"contact_person":{"name":"Merchant","phone":"639123456789"},"taking_amount":"0.00","buyout_amount":"0.00","note":null,"packages":[],"is_cod_cash_voucher_required":false,"is_order_payment_here":false,"building_number":null,"entrance_number":null,"intercom_code":null,"floor_number":null,"apartment_number":null,"invisible_mile_navigation_instructions":null},{"point_type":"plain","point_id":null,"client_order_id":null,"address":"32nd
51
+ St. cor. 9th Ave, Taguig, Metro Manila, 32nd St, Taguig, Metro Manila, Philippines","latitude":"14.5528233","longitude":"121.0519364","required_start_datetime":"2020-05-12T21:22:18+08:00","required_finish_datetime":"2020-05-12T23:00:00+08:00","arrival_start_datetime":null,"arrival_finish_datetime":null,"courier_visit_datetime":null,"contact_person":{"name":"Reciever","phone":"639123456789"},"taking_amount":"0.00","buyout_amount":"0.00","note":null,"packages":[],"is_cod_cash_voucher_required":false,"is_order_payment_here":false,"building_number":null,"entrance_number":null,"intercom_code":null,"floor_number":null,"apartment_number":null,"invisible_mile_navigation_instructions":null}],"payment_amount":"170.00","delivery_fee_amount":"170.00","intercity_delivery_fee_amount":"0.00","weight_fee_amount":"0.00","insurance_amount":"0.00","insurance_fee_amount":"0.00","loading_fee_amount":"0.00","money_transfer_fee_amount":"0.00","suburban_delivery_fee_amount":"0.00","overnight_fee_amount":"0.00","discount_amount":"0.00","backpayment_amount":"0.00","cod_fee_amount":"0.00","backpayment_photo_url":null,"itinerary_document_url":null,"waybill_document_url":null,"courier":null,"is_motobox_required":false},"warnings":[],"parameter_warnings":null}'
52
+ http_version: null
53
+ recorded_at: Tue, 12 May 2020 13:22:19 GMT
54
+ recorded_with: VCR 5.1.0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://robotapitest.mrspeedy.ph/api/business/1.1/create-order
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"matter":"Food","vehicle_type_id":8,"points":[{"address":"Capitol
9
+ Park Homes, 71 Berlin Avenue, Matandang Balara, Quezon City, Metro Manila","contact_person":{"name":"Merchant","phone":"639123456789"},"packages":[]},{"address":"Unit
10
+ 802, EcoTower, 32nd Street corner 9th Avenue, BGC, Taguig, 1634 Metro Manila","contact_person":{"name":"Reciever","phone":"639123456789"},"packages":[]}]}'
11
+ headers:
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ Host:
19
+ - robotapitest.mrspeedy.ph
20
+ X-Dv-Auth-Token:
21
+ - 70B4ABCA8A35AC50E1585E27F217DF160F740D46
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Server:
28
+ - nginx
29
+ Date:
30
+ - Tue, 12 May 2020 13:22:21 GMT
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Transfer-Encoding:
34
+ - chunked
35
+ Connection:
36
+ - keep-alive
37
+ Vary:
38
+ - Accept-Encoding
39
+ X-Frame-Options:
40
+ - DENY
41
+ X-Content-Type-Options:
42
+ - nosniff
43
+ X-Xss-Protection:
44
+ - 1; mode=block;
45
+ Strict-Transport-Security:
46
+ - max-age=31536000; includeSubDomains
47
+ body:
48
+ encoding: ASCII-8BIT
49
+ string: '{"is_successful":true,"order":{"order_id":77802,"order_name":"77802","vehicle_type_id":8,"created_datetime":"2020-05-12T21:22:21+08:00","finish_datetime":null,"status":"new","matter":"Food","total_weight_kg":0,"is_client_notification_enabled":false,"is_contact_person_notification_enabled":false,"loaders_count":0,"backpayment_details":null,"points":[{"point_type":"plain","point_id":203156,"client_order_id":null,"address":"Zurich
50
+ Ave, Matandang Balara, Quezon City, Metro Manila, Philippines","latitude":"14.6710069","longitude":"121.0944076","required_start_datetime":"2020-05-12T21:22:21+08:00","required_finish_datetime":"2020-05-12T22:30:00+08:00","arrival_start_datetime":null,"arrival_finish_datetime":null,"courier_visit_datetime":null,"contact_person":{"name":"Merchant","phone":"639123456789"},"taking_amount":"0.00","buyout_amount":"0.00","note":null,"packages":[],"is_cod_cash_voucher_required":false,"is_order_payment_here":false,"building_number":null,"entrance_number":null,"intercom_code":null,"floor_number":null,"apartment_number":null,"invisible_mile_navigation_instructions":null},{"point_type":"plain","point_id":203157,"client_order_id":null,"address":"32nd
51
+ St. cor. 9th Ave, Taguig, Metro Manila, 32nd St, Taguig, Metro Manila, Philippines","latitude":"14.5528233","longitude":"121.0519364","required_start_datetime":"2020-05-12T21:22:21+08:00","required_finish_datetime":"2020-05-12T23:00:00+08:00","arrival_start_datetime":null,"arrival_finish_datetime":null,"courier_visit_datetime":null,"contact_person":{"name":"Reciever","phone":"639123456789"},"taking_amount":"0.00","buyout_amount":"0.00","note":null,"packages":[],"is_cod_cash_voucher_required":false,"is_order_payment_here":false,"building_number":null,"entrance_number":null,"intercom_code":null,"floor_number":null,"apartment_number":null,"invisible_mile_navigation_instructions":null}],"payment_amount":"170.00","delivery_fee_amount":"170.00","intercity_delivery_fee_amount":"0.00","weight_fee_amount":"0.00","insurance_amount":"0.00","insurance_fee_amount":"0.00","loading_fee_amount":"0.00","money_transfer_fee_amount":"0.00","suburban_delivery_fee_amount":"0.00","overnight_fee_amount":"0.00","discount_amount":"0.00","backpayment_amount":"0.00","cod_fee_amount":"0.00","backpayment_photo_url":null,"itinerary_document_url":null,"waybill_document_url":null,"courier":null,"is_motobox_required":false}}'
52
+ http_version: null
53
+ recorded_at: Tue, 12 May 2020 13:22:21 GMT
54
+ recorded_with: VCR 5.1.0
@@ -0,0 +1,7 @@
1
+ require "mr_speedy_ruby/version"
2
+ require "mr_speedy_ruby/client"
3
+
4
+ # Mr Speedy Namespace Module
5
+ module MrSpeedyRuby
6
+ class Error < StandardError; end
7
+ end
@@ -0,0 +1,72 @@
1
+ module MrSpeedyRuby
2
+ # Mr Speedy Abstract Class
3
+ # @since 0.1.0
4
+ class Base
5
+ require "net/http"
6
+ require "uri"
7
+ require "json"
8
+
9
+ AUTH_TOKEN_HEADER="X-DV-Auth-Token".freeze
10
+ PRODUCTION_BASE_URL="http://robot.mrspeedy.ph".freeze
11
+ STAGING_BASE_URL="https://robotapitest.mrspeedy.ph".freeze
12
+
13
+ # Endpoint Generator
14
+ # @since v0.1.0
15
+ #
16
+ # @private
17
+ #
18
+ # @param [String] endpoint request endpoint
19
+ # @param [Boolean] sandbox sandbox environment indicator
20
+ #
21
+ # @return [String] request endpoint
22
+ def build_url(endpoint, sandbox)
23
+ base_url = sandbox ? STAGING_BASE_URL : PRODUCTION_BASE_URL
24
+ base_url + endpoint
25
+ end
26
+
27
+ # Send Post Request
28
+ # @since v0.1.0
29
+ # @param endpoint [String] request endpoint
30
+ # @param token [String] app token
31
+ # @param payload [Hash] message payload
32
+ #
33
+ # @return [Json] response
34
+ def post(endpoint:, token:, payload:)
35
+ response = send_request("post", endpoint, token, payload)
36
+
37
+ response_body = JSON.parse(response.body)
38
+ response_body
39
+ end
40
+
41
+ private
42
+
43
+ # Request sender
44
+ # @since v0.1.0
45
+ #
46
+ # @private
47
+ #
48
+ # @param endpoint [String] request endpoint
49
+ # @param token [String] app token
50
+ # @param payload [Hash] message payload
51
+ #
52
+ # @return [Json] request response
53
+ def send_request(method, endpoint, token, payload)
54
+ uri = URI.parse(endpoint)
55
+
56
+ request = if method == "post"
57
+ Net::HTTP::Post.new(uri)
58
+ else
59
+ Net::HTTP::Get.new(uri)
60
+ end
61
+
62
+ request.add_field(AUTH_TOKEN_HEADER, token)
63
+
64
+ request.body = JSON.dump payload
65
+ options = { use_ssl: uri.scheme == "https" }
66
+
67
+ Net::HTTP.start(uri.hostname, uri.port, options) do |http|
68
+ http.request(request)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,164 @@
1
+ require "mr_speedy_ruby/base"
2
+ require "mr_speedy_ruby/lib/hash_refinement"
3
+
4
+ module MrSpeedyRuby
5
+ # Mr Speedy API Client
6
+ # @since 0.1.0
7
+ class Client < Base
8
+ using MrSpeedyRuby::Lib::HashRefinement
9
+ # Vehicle Types
10
+ # @see https://apitest.mrspeedy.ph/business-api/doc#vehicle-types
11
+ CAR = 7.freeze
12
+ MOTORBIKE = 8.freeze
13
+
14
+ # @attr_reader [String] token authentication token
15
+ # @attr_reader [String] version api version
16
+ attr_reader :token, :version
17
+
18
+ def initialize(token:, version: "1.1")
19
+ @token = token
20
+ @version = version
21
+ end
22
+
23
+ # Delivery Fee Calculation
24
+ # @since 0.1.0
25
+ #
26
+ # @param [Hash] pickup pickup location
27
+ # @param pickup [String] :address delivery parcel pickup address
28
+ # @param pickup [Hash] :contact_person delivery parcel pickup contact person
29
+ # details
30
+ # @param contact_person [String] :name delivery parcel pickup contact person
31
+ # name
32
+ # @param contact_person [String] :phone delivery parcel pickup contact person
33
+ # contact details(required)
34
+ #
35
+ # @param [Hash] delivery location
36
+ # @param delivery [String] :address delivery parcel address
37
+ # @param delivery [Hash] :contact_person delivery parcel contact person details
38
+ # @param contact_person [String] :name delivery parcel contact person name
39
+ # @param contact_person [String] :phone delivery parcel contact person
40
+ # contact details(required)
41
+ #
42
+ # @param [Hash] opts additional details
43
+ # @param opts [String] :matter delivery parcel type
44
+ #
45
+ # @param [Boolean] sandbox sandbox identifier(default false)
46
+ #
47
+ # @see https://apitest.mrspeedy.ph/business-api/doc#calculate-order
48
+ def calculate_fees(pickup:, delivery:, opts: {}, sandbox: false)
49
+ validate_delivery(details: pickup)
50
+ validate_delivery(details: delivery)
51
+
52
+ opts.deep_symbolize_keys.assert_required_keys(option_keys)
53
+
54
+ endpoint = "/api/business/#{version}/calculate-order"
55
+ url = build_url(endpoint, sandbox)
56
+ payload = build_payload(opts: opts, pickup: pickup, delivery: delivery)
57
+
58
+ post(endpoint: url, token: @token, payload: payload)
59
+ end
60
+
61
+ # Place Order
62
+ # @since 0.1.0
63
+ #
64
+ # @param [Hash] pickup pickup location
65
+ # @param pickup [String] :address delivery parcel pickup address
66
+ # @param pickup [Hash] :contact_person delivery parcel pickup contact person
67
+ # details
68
+ # @param contact_person [String] :name delivery parcel pickup contact person
69
+ # name
70
+ # @param contact_person [String] :phone delivery parcel pickup contact person
71
+ # contact details(required)
72
+ #
73
+ # @param [Hash] delivery location
74
+ # @param delivery [String] :address delivery parcel address
75
+ # @param delivery [Hash] :contact_person delivery parcel contact person details
76
+ # @param contact_person [String] :name delivery parcel contact person name
77
+ # @param contact_person [String] :phone delivery parcel contact person
78
+ # contact details(required)
79
+ #
80
+ # @param [Hash] opts additional details
81
+ # @param opts [String] :matter delivery parcel type
82
+ #
83
+ # @param [Boolean] sandbox sandbox identifier(default false)
84
+ #
85
+ # @see https://apitest.mrspeedy.ph/business-api/doc#create-order
86
+ def place_order(pickup:, delivery:, opts: {}, sandbox: false)
87
+ validate_delivery(details: pickup)
88
+ validate_delivery(details: delivery)
89
+
90
+ opts.deep_symbolize_keys.assert_required_keys(option_keys)
91
+
92
+ endpoint = "/api/business/#{version}/create-order"
93
+ url = build_url(endpoint, sandbox)
94
+ payload = build_payload(opts: opts, pickup: pickup, delivery: delivery)
95
+
96
+ post(endpoint: url, token: @token, payload: payload)
97
+ end
98
+
99
+ private
100
+
101
+ # Options Required Keys
102
+ # @since 0.1.0
103
+ #
104
+ # @private
105
+ #
106
+ # @return [Array<String>]
107
+ def option_keys
108
+ %i[matter]
109
+ end
110
+
111
+ # Points Required Keys
112
+ #
113
+ # @private
114
+ #
115
+ # @return [Array<String>]
116
+ def points_keys
117
+ %i[packages]
118
+ end
119
+
120
+ # Contact Person Required Keys
121
+ # @since 0.1.0
122
+ #
123
+ # @private
124
+ #
125
+ # @return [Array<String>]
126
+ def contact_person_keys
127
+ %i[phone]
128
+ end
129
+
130
+ # Package Required Keys
131
+ #
132
+ # @private
133
+ #
134
+ # @return [Array<String>]
135
+ def package_keys
136
+ %i[ware_code description items_count item_payment_amount]
137
+ end
138
+
139
+ # Delivery Details Validator
140
+ # @since 0.1.0
141
+ #
142
+ # @private
143
+ def validate_delivery(details:)
144
+ delivery_details = details.deep_symbolize_keys
145
+ delivery_details.assert_required_keys(points_keys)
146
+ delivery_details[:contact_person].to_h.assert_required_keys(contact_person_keys)
147
+ end
148
+
149
+ # Payload Builder
150
+ # @since 0.1.0
151
+ #
152
+ # @private
153
+ #
154
+ # @return [Hash]
155
+ def build_payload(opts:, pickup:, delivery:)
156
+ # Set MOTORBIKE as default vehicle
157
+ vehicle = opts[:vehicle_type_id] || MOTORBIKE
158
+ opts.merge({
159
+ vehicle_type_id: vehicle,
160
+ points: [pickup, delivery]
161
+ })
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,39 @@
1
+ module MrSpeedyRuby
2
+ module Lib
3
+ # Hash Module Refinement
4
+ # https://medium.com/rubycademy/refine-and-using-methods-in-ruby-part-i-2aef6d7a4325
5
+ module HashRefinement
6
+ extend self
7
+
8
+ def symbolize_recursive(hash)
9
+ {}.tap do |h|
10
+ hash.each { |key, value| h[key.to_sym] = transform(value) }
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def transform(thing)
17
+ case thing
18
+ when Hash; symbolize_recursive(thing)
19
+ when Array; thing.map { |v| transform(v) }
20
+ else; thing
21
+ end
22
+ end
23
+
24
+ refine Hash do
25
+ def deep_symbolize_keys
26
+ HashRefinement.symbolize_recursive(self)
27
+ end
28
+
29
+ # Ensure Hash parameters are completed
30
+ # https://coderwall.com/p/ne7owq/validating-hash-params-in-ruby
31
+ def assert_required_keys(*keys)
32
+ keys.flatten.each do |key|
33
+ raise ArgumentError, "Required key: #{key.inspect}" unless key?(key)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module MrSpeedyRuby
2
+ VERSION = "1.0.0-alpha.2"
3
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "mr_speedy_ruby/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "mr_speedy_ruby"
9
+ spec.version = MrSpeedyRuby::VERSION
10
+ spec.authors = ["Peter John Alvarado"]
11
+ spec.email = ["peterjohn@gorated.ph"]
12
+
13
+ spec.summary = "Mr.speedy api integration for ruby"
14
+ spec.description = "Provides services for integrating mr.speedy in your app"
15
+ spec.homepage = "https://github.com/redjoker011/mr_speedy_ruby"
16
+ spec.license = "MIT"
17
+ spec.extra_rdoc_files = Dir["README.md", "CHANGELOG.md", "LICENSE.txt"]
18
+ spec.rdoc_options += [
19
+ "--title", "MrSpeedyRuby - mr.speedy api integration for ruby",
20
+ "--main", "README.md",
21
+ "--line-numbers",
22
+ "--inline-source",
23
+ "--quiet"
24
+ ]
25
+
26
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
27
+
28
+ spec.metadata["homepage_uri"] = spec.homepage
29
+ spec.metadata["source_code_uri"] = "https://github.com/redjoker011/mr_speedy_ruby"
30
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
31
+
32
+ # Specify which files should be added to the gem when it is released.
33
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
35
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
36
+ end
37
+ spec.bindir = "exe"
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ["lib"]
40
+
41
+ spec.add_development_dependency "bundler", "~> 2.0"
42
+ spec.add_development_dependency "rake", "~> 13.0"
43
+ spec.add_development_dependency "minitest", "~> 5.0"
44
+ spec.add_development_dependency "vcr", "~> 5.1.0"
45
+ spec.add_development_dependency "webmock", "~> 3.8.3"
46
+ spec.add_development_dependency "pry"
47
+ spec.add_development_dependency "awesome_print"
48
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mr_speedy_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.alpha.2
5
+ platform: ruby
6
+ authors:
7
+ - Peter John Alvarado
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 5.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 5.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.8.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.8.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: awesome_print
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Provides services for integrating mr.speedy in your app
112
+ email:
113
+ - peterjohn@gorated.ph
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - README.md
118
+ - LICENSE.txt
119
+ files:
120
+ - ".gitignore"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - fixtures/vcr_cassettes/delivery_fee.yml
131
+ - fixtures/vcr_cassettes/place_order.yml
132
+ - lib/mr_speedy_ruby.rb
133
+ - lib/mr_speedy_ruby/base.rb
134
+ - lib/mr_speedy_ruby/client.rb
135
+ - lib/mr_speedy_ruby/lib/hash_refinement.rb
136
+ - lib/mr_speedy_ruby/version.rb
137
+ - mr_speedy_ruby.gemspec
138
+ homepage: https://github.com/redjoker011/mr_speedy_ruby
139
+ licenses:
140
+ - MIT
141
+ metadata:
142
+ homepage_uri: https://github.com/redjoker011/mr_speedy_ruby
143
+ source_code_uri: https://github.com/redjoker011/mr_speedy_ruby
144
+ post_install_message:
145
+ rdoc_options:
146
+ - "--title"
147
+ - MrSpeedyRuby - mr.speedy api integration for ruby
148
+ - "--main"
149
+ - README.md
150
+ - "--line-numbers"
151
+ - "--inline-source"
152
+ - "--quiet"
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">"
163
+ - !ruby/object:Gem::Version
164
+ version: 1.3.1
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.7.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Mr.speedy api integration for ruby
171
+ test_files: []