novaposhta2 0.0.1
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 +7 -0
- data/lib/novaposhta2.rb +31 -0
- data/lib/novaposhta2/base.rb +9 -0
- data/lib/novaposhta2/city.rb +59 -0
- data/lib/novaposhta2/configuration.rb +8 -0
- data/lib/novaposhta2/package.rb +62 -0
- data/lib/novaposhta2/person.rb +26 -0
- data/lib/novaposhta2/post.rb +24 -0
- data/lib/novaposhta2/warehouse.rb +14 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38cb5589cccece09ff4c03ff6afad4d2af543183
|
4
|
+
data.tar.gz: 56e5ff8e69fde1c4eb47a9b5384c00b36b81d9d3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6122f742275a38752e198602fadf1f48b8aac7a4723d5a9413bab77ad6b19ffecb064db444592f5d9f838d9f9fa7561a8a1144b7e47ec34a55752ed1a2d3988
|
7
|
+
data.tar.gz: 3a15684d92859fa4609f89163387ecb70fc79a521228890d662c46a6091e53da17e8bb0a8b5dbbf807f0d5802b8cdaa06537e0bfb1d4d1cc617c25ab92d5169c
|
data/lib/novaposhta2.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'logger'
|
4
|
+
require 'novaposhta2/configuration'
|
5
|
+
require 'novaposhta2/post'
|
6
|
+
require 'novaposhta2/base'
|
7
|
+
require 'novaposhta2/person'
|
8
|
+
require 'novaposhta2/city'
|
9
|
+
require 'novaposhta2/warehouse'
|
10
|
+
require 'novaposhta2/package'
|
11
|
+
|
12
|
+
module Novaposhta2
|
13
|
+
def self.configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure
|
18
|
+
yield configuration
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.[](index)
|
22
|
+
City[index]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.track(tracking)
|
26
|
+
Package.track(tracking)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Novaposhta2
|
2
|
+
class City < Base
|
3
|
+
attr_reader :description, :description_ru, :ref
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@description = params['Description']
|
7
|
+
@description_ru = params['DescriptionRu']
|
8
|
+
@ref = params['Ref']
|
9
|
+
end
|
10
|
+
|
11
|
+
def warehouses(number = nil)
|
12
|
+
@warehouses ||= post('Address', 'getWarehouses', CityRef: @ref)['data'].map do |data|
|
13
|
+
Warehouse.new(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
if number.nil?
|
17
|
+
@warehouses
|
18
|
+
else
|
19
|
+
@warehouses.find {|w| w.number == number}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
alias [] warehouses
|
24
|
+
|
25
|
+
def person(firstname, lastname, phone)
|
26
|
+
Person.new(self, firstname, lastname, phone)
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
|
31
|
+
def find_by_ref(ref)
|
32
|
+
query(Ref: ref).first
|
33
|
+
end
|
34
|
+
|
35
|
+
def match(name)
|
36
|
+
query(FindByString: name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def find(name)
|
40
|
+
m = match(name)
|
41
|
+
m.count == 1 ? m[0] : nil
|
42
|
+
end
|
43
|
+
|
44
|
+
alias [] find
|
45
|
+
|
46
|
+
def all
|
47
|
+
match(nil)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def self.query(params)
|
54
|
+
post('Address', 'getCities', params)['data'].map do |data|
|
55
|
+
City.new(data)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Novaposhta2
|
2
|
+
class Package < Base
|
3
|
+
attr_accessor :address, :recipient, :options, :ref, :tracking
|
4
|
+
|
5
|
+
def initialize(address, recipient, options = {})
|
6
|
+
@address = address
|
7
|
+
@recipient = recipient
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def rate
|
12
|
+
post('InternetDocument', 'getDocumentPrice', params)['data'][0]['Cost'].to_i
|
13
|
+
end
|
14
|
+
|
15
|
+
def save
|
16
|
+
data = post('InternetDocument', 'save', params)
|
17
|
+
|
18
|
+
@ref = data['data'][0]['Ref']
|
19
|
+
@tracking = data['data'][0]['IntDocNumber']
|
20
|
+
end
|
21
|
+
|
22
|
+
def print
|
23
|
+
"https://my.novaposhta.ua/orders/printMarkings/orders/#{@ref}/type/html/apiKey/#{config.api_key}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def track
|
27
|
+
self.class.track(@tracking)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.track(tracking)
|
31
|
+
post('InternetDocument', 'documentsTracking', Documents: [tracking.to_s])['data'][0]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def params
|
37
|
+
{
|
38
|
+
DateTime: (options[:date] || Time.now).strftime('%d.%m.%Y'),
|
39
|
+
ServiceType: 'WarehouseWarehouse',
|
40
|
+
Sender: config.sender['ref'],
|
41
|
+
CitySender: config.sender['city'],
|
42
|
+
SenderAddress: config.sender['address'],
|
43
|
+
ContactSender: config.sender['contact'],
|
44
|
+
SendersPhone: config.sender['phone'],
|
45
|
+
Recipient: @recipient.ref,
|
46
|
+
CityRecipient: @recipient.city.ref,
|
47
|
+
RecipientAddress: @address.ref,
|
48
|
+
ContactRecipient: @recipient.contact_ref,
|
49
|
+
RecipientsPhone: @recipient.phone,
|
50
|
+
PaymentMethod: :Cash || options[:payment_method],
|
51
|
+
PayerType: :Sender || options[:payer_type],
|
52
|
+
Cost: options[:cost],
|
53
|
+
SeatsAmount: 1 || options[:seats],
|
54
|
+
Description: options[:description],
|
55
|
+
CargoType: 'Cargo',
|
56
|
+
Weight: options[:weight],
|
57
|
+
VolumeGeneral: options[:volume] || options[:width] * options[:height] * options[:depth],
|
58
|
+
InfoRegClientBarcodes: options[:internal_number]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Novaposhta2
|
2
|
+
class Person < Base
|
3
|
+
attr_reader :city, :firstname, :lastname, :phone, :ref, :contact_ref
|
4
|
+
|
5
|
+
def initialize(city, firstname, lastname, phone)
|
6
|
+
@city, @firstname, @lastname, @phone = city, firstname, lastname, phone
|
7
|
+
|
8
|
+
data = post('Counterparty', 'save',
|
9
|
+
{
|
10
|
+
CityRef: @city.ref,
|
11
|
+
FirstName: @firstname,
|
12
|
+
LastName: @lastname,
|
13
|
+
Phone: @phone,
|
14
|
+
CounterpartyType: :PrivatePerson,
|
15
|
+
CounterpartyProperty: :Recipient
|
16
|
+
})['data'][0]
|
17
|
+
|
18
|
+
@ref = data['Ref']
|
19
|
+
@contact_ref = data['ContactPerson']['data'][0]['Ref']
|
20
|
+
end
|
21
|
+
|
22
|
+
def package(address, options)
|
23
|
+
Package.new(address, self, options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Novaposhta2
|
2
|
+
module Post
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def post(model, method, properties)
|
8
|
+
post_json({apiKey: Novaposhta2.configuration.api_key, modelName: model, calledMethod: method, methodProperties: properties}.to_json)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def post_json(data)
|
13
|
+
u = URI('https://api.novaposhta.ua/v2.0/json/')
|
14
|
+
r = Net::HTTP::Post.new(u.path)
|
15
|
+
r.add_field 'Content-Type', 'application/json'
|
16
|
+
r.body = data
|
17
|
+
rs = Net::HTTP.start(u.hostname, u.port, use_ssl: u.scheme == 'https') {|h| h.request(r)}
|
18
|
+
js = JSON.parse rs.body
|
19
|
+
raise js['errors'].to_s if js['errors'].any?
|
20
|
+
raise 'Novaposhta feed request failed' unless js['success']
|
21
|
+
js
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Novaposhta2
|
2
|
+
class Warehouse < Base
|
3
|
+
attr_reader :description, :description_ru, :ref, :number, :longtitude, :latitude
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@description = params['Description']
|
7
|
+
@description_ru = params['DescriptionRu']
|
8
|
+
@ref = params['Ref']
|
9
|
+
@number = params['Number'].to_i
|
10
|
+
@longtitude = params['Longtitude']
|
11
|
+
@latitude = params['Latitude']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: novaposhta2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Kukareka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Nova Poshta is a popular local shipping provider in Ukraine (https://novaposhta.ua/).
|
14
|
+
email: oleg@kukareka.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/novaposhta2.rb
|
20
|
+
- lib/novaposhta2/base.rb
|
21
|
+
- lib/novaposhta2/city.rb
|
22
|
+
- lib/novaposhta2/configuration.rb
|
23
|
+
- lib/novaposhta2/package.rb
|
24
|
+
- lib/novaposhta2/person.rb
|
25
|
+
- lib/novaposhta2/post.rb
|
26
|
+
- lib/novaposhta2/warehouse.rb
|
27
|
+
homepage: https://github.com/kukareka/novaposhta2
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project: novaposhta2
|
47
|
+
rubygems_version: 2.2.2
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Novaposhta API 2.0
|
51
|
+
test_files: []
|