novaposhta2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38cb5589cccece09ff4c03ff6afad4d2af543183
4
- data.tar.gz: 56e5ff8e69fde1c4eb47a9b5384c00b36b81d9d3
3
+ metadata.gz: e13968415cc81354bf69c306d9484608256340e2
4
+ data.tar.gz: 62e993aa3d81cea2fbf646c62e7f0e8e0c29492e
5
5
  SHA512:
6
- metadata.gz: b6122f742275a38752e198602fadf1f48b8aac7a4723d5a9413bab77ad6b19ffecb064db444592f5d9f838d9f9fa7561a8a1144b7e47ec34a55752ed1a2d3988
7
- data.tar.gz: 3a15684d92859fa4609f89163387ecb70fc79a521228890d662c46a6091e53da17e8bb0a8b5dbbf807f0d5802b8cdaa06537e0bfb1d4d1cc617c25ab92d5169c
6
+ metadata.gz: eee5c85f5011ba2f45f0be48befe7ed1224a8706e8671a2eec35e8bca67fbf605964066d1a4e2a4b656085b85627227fa27f248b2378c6744977ce0a74f509e2
7
+ data.tar.gz: 0a5fa114f68ffabceb81bf67473b21cb53bac3d005cde75280a8a54be57dc0e99e61486b7bb9237792326c322022decb3a0eee45aee3abc6131acfd8b865d7c8
@@ -9,19 +9,38 @@ require 'novaposhta2/city'
9
9
  require 'novaposhta2/warehouse'
10
10
  require 'novaposhta2/package'
11
11
 
12
+ # Novaposhta API 2.0 Gem.
13
+ # == Configuration
14
+ #
15
+ # Novaposhta2.configure do |config|
16
+ # config.api_key = 'Your api key'
17
+ # config.sender = {
18
+ # ref: 'Sender reference',
19
+ # city: 'City reference',
20
+ # address: 'Sender warehouse reference',
21
+ # contact: 'Sender contact reference',
22
+ # phone: 'Sender phone',
23
+ # }
24
+ # end
25
+ #
26
+
12
27
  module Novaposhta2
13
- def self.configuration
28
+
29
+ def self.configuration # :nodoc:
14
30
  @configuration ||= Configuration.new
15
31
  end
16
32
 
17
- def self.configure
33
+ def self.configure # :nodoc:
18
34
  yield configuration
19
35
  end
20
36
 
21
- def self.[](index)
22
- City[index]
37
+ # Returns a city found by name or part of the name.
38
+ # If more than one city match +name+ - returns nil.
39
+ def self.[](name)
40
+ City[name]
23
41
  end
24
42
 
43
+ # Returns shipment tracking information by tracking number.
25
44
  def self.track(tracking)
26
45
  Package.track(tracking)
27
46
  end
@@ -1,7 +1,9 @@
1
1
  module Novaposhta2
2
- class Base
2
+ class Base # :nodoc:
3
3
  include Post
4
4
 
5
+ private
6
+
5
7
  def config
6
8
  Novaposhta2.configuration
7
9
  end
@@ -1,6 +1,7 @@
1
1
  module Novaposhta2
2
+ # Represents a known city.
2
3
  class City < Base
3
- attr_reader :description, :description_ru, :ref
4
+ attr_reader :description, :description_ru, :ref # :nodoc:
4
5
 
5
6
  def initialize(params)
6
7
  @description = params['Description']
@@ -8,6 +9,7 @@ module Novaposhta2
8
9
  @ref = params['Ref']
9
10
  end
10
11
 
12
+ # Lists all warehouses or returns warehouse by number.
11
13
  def warehouses(number = nil)
12
14
  @warehouses ||= post('Address', 'getWarehouses', CityRef: @ref)['data'].map do |data|
13
15
  Warehouse.new(data)
@@ -22,20 +24,25 @@ module Novaposhta2
22
24
 
23
25
  alias [] warehouses
24
26
 
27
+ # Creates new person that belongs to the city.
25
28
  def person(firstname, lastname, phone)
26
29
  Person.new(self, firstname, lastname, phone)
27
30
  end
28
31
 
29
32
  class << self
30
33
 
34
+ # Returns city matching +ref+.
31
35
  def find_by_ref(ref)
32
36
  query(Ref: ref).first
33
37
  end
34
38
 
39
+ # Returns all cities matching a pattern.
35
40
  def match(name)
36
41
  query(FindByString: name)
37
42
  end
38
43
 
44
+ # Returns a city by name or part of the name.
45
+ # If more than one city match a +name+ - returns nil.
39
46
  def find(name)
40
47
  m = match(name)
41
48
  m.count == 1 ? m[0] : nil
@@ -43,6 +50,7 @@ module Novaposhta2
43
50
 
44
51
  alias [] find
45
52
 
53
+ # Returns list of all known cities.
46
54
  def all
47
55
  match(nil)
48
56
  end
@@ -1,5 +1,5 @@
1
1
  module Novaposhta2
2
- class Configuration
2
+ class Configuration # :nodoc:
3
3
  attr_accessor :api_key, :sender
4
4
  def initialize
5
5
  @api_key = ENV['NOVAPOSHTA_API_KEY']
@@ -1,17 +1,31 @@
1
1
  module Novaposhta2
2
+
3
+ # Represents a package.
4
+ # == Options
5
+ # [cost] *Mandatory*. Cost of the package contents, for insurance needs.
6
+ # [description] *Mandatory*. Description of package contents.
7
+ # [internal_number] Internal order number.
8
+ # [payer_type] *Sender* of *Recipient*. Default: *Sender*.
9
+ # [payment_method] *Cash* or *NonCash*. Default: *Cash*.
10
+ # [seats] Number of boxes. Default: *1*.
11
+ # [volume] *Mandatory*. Volume of the package in *cm*
12
+ # [weight] *Mandatory*. Weight of the package in *kg*.
13
+
2
14
  class Package < Base
3
- attr_accessor :address, :recipient, :options, :ref, :tracking
15
+ attr_accessor :address, :recipient, :options, :ref, :tracking # :nodoc:
4
16
 
5
- def initialize(address, recipient, options = {})
17
+ def initialize(address, recipient, options = {}) # :nodoc:
6
18
  @address = address
7
19
  @recipient = recipient
8
20
  @options = options
9
21
  end
10
22
 
23
+ # Get the shipping rate.
11
24
  def rate
12
25
  post('InternetDocument', 'getDocumentPrice', params)['data'][0]['Cost'].to_i
13
26
  end
14
27
 
28
+ # Commit the package.
15
29
  def save
16
30
  data = post('InternetDocument', 'save', params)
17
31
 
@@ -19,14 +33,17 @@ module Novaposhta2
19
33
  @tracking = data['data'][0]['IntDocNumber']
20
34
  end
21
35
 
36
+ # Print package markings.
22
37
  def print
23
38
  "https://my.novaposhta.ua/orders/printMarkings/orders/#{@ref}/type/html/apiKey/#{config.api_key}"
24
39
  end
25
40
 
41
+ # Get package tracking information.
26
42
  def track
27
43
  self.class.track(@tracking)
28
44
  end
29
45
 
46
+ # Get tracking information by tracking number.
30
47
  def self.track(tracking)
31
48
  post('InternetDocument', 'documentsTracking', Documents: [tracking.to_s])['data'][0]
32
49
  end
@@ -1,8 +1,9 @@
1
1
  module Novaposhta2
2
+ # Represents a package recipient.
2
3
  class Person < Base
3
- attr_reader :city, :firstname, :lastname, :phone, :ref, :contact_ref
4
+ attr_reader :city, :firstname, :lastname, :phone, :ref, :contact_ref # :nodoc:
4
5
 
5
- def initialize(city, firstname, lastname, phone)
6
+ def initialize(city, firstname, lastname, phone) #:nodoc:
6
7
  @city, @firstname, @lastname, @phone = city, firstname, lastname, phone
7
8
 
8
9
  data = post('Counterparty', 'save',
@@ -19,6 +20,7 @@ module Novaposhta2
19
20
  @contact_ref = data['ContactPerson']['data'][0]['Ref']
20
21
  end
21
22
 
23
+ # Creates a new package for the person.
22
24
  def package(address, options)
23
25
  Package.new(address, self, options)
24
26
  end
@@ -1,5 +1,5 @@
1
1
  module Novaposhta2
2
- module Post
2
+ module Post # :nodoc:
3
3
  def self.included(base)
4
4
  base.extend(self)
5
5
  end
@@ -1,8 +1,9 @@
1
1
  module Novaposhta2
2
+ # Represents a warehouse.
2
3
  class Warehouse < Base
3
- attr_reader :description, :description_ru, :ref, :number, :longtitude, :latitude
4
+ attr_reader :description, :description_ru, :ref, :number, :longtitude, :latitude #:nodoc:
4
5
 
5
- def initialize(params)
6
+ def initialize(params) #:nodoc:
6
7
  @description = params['Description']
7
8
  @description_ru = params['DescriptionRu']
8
9
  @ref = params['Ref']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: novaposhta2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Kukareka