tuffnells_api 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccd50044f244f59f463c3e1fbcf3dacf21f980ee
4
+ data.tar.gz: feee571c04c3f8a46efbb5272d5762226efdd95b
5
+ SHA512:
6
+ metadata.gz: bd1d5e7a0302202c74483a689c29ed89ce00cfb0f5f52f707bd6eb009c5fbe78a63a4a845183660190bc76859d10d01d91a147bf2f7fce9089199c9e0295121f
7
+ data.tar.gz: '081d009ccb72feb53ab339d01a39ef3c962de310e9ea10ad392b47b217e8c2a706895cd4a67971f000ec8c0220a842b6abcf665c9db8f398c5e085533475a708'
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tuffnells_api.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jamie Barton
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,47 @@
1
+ # TuffnellsApi
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'tuffnells_api'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ gem install tuffnells_api
18
+
19
+ ## Configuration
20
+ Before making a request, you must configure an account code.
21
+
22
+ ```ruby
23
+ TuffnellsApi.configure do |config|
24
+ config.account_code = 123456
25
+ end
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ @consigment = TuffnellsApi::Consignment.find(consignment_no)
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ 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).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tuffnells_api.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tuffnells_api"
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
@@ -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,19 @@
1
+ require "tuffnells_api/version"
2
+ require "tuffnells_api/configuration"
3
+ require "tuffnells_api/base"
4
+ require "tuffnells_api/consignment"
5
+ require "tuffnells_api/errors"
6
+
7
+ module TuffnellsApi
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield configuration
18
+ end
19
+ end
@@ -0,0 +1,57 @@
1
+ require 'uri'
2
+ require 'open-uri'
3
+ require "happymapper"
4
+ require 'tuffnells_api/tracking_record'
5
+
6
+ module TuffnellsApi
7
+ class Base
8
+ include HappyMapper
9
+
10
+ attr_reader :account_code
11
+
12
+ def initialize consignment_no
13
+ @consignment_no = consignment_no
14
+ @account_code = TuffnellsApi.configuration.account_code
15
+ read_timeout = TuffnellsApi.configuration.read_timeout || 5
16
+
17
+ proxy = TuffnellsApi.configuration.proxy
18
+
19
+ request = Nokogiri::XML(open(base_uri,
20
+ proxy_http_basic_authentication: proxy,
21
+ read_timeout: read_timeout
22
+ ))
23
+
24
+ @response = TuffnellsApi::TrackingRecord.parse(request, single: true)
25
+ end
26
+
27
+ def postcode
28
+ @response.delivery_address.postcode
29
+ end
30
+
31
+ def total_pieces
32
+ @response.consignment_information.pieces
33
+ end
34
+
35
+ def delivery_status
36
+ @response.movement_information.movements.last.description
37
+ end
38
+
39
+ def signed_by
40
+ @response.timed_information.deliveries.last.signature
41
+ end
42
+
43
+ def pod_image
44
+ @response.image_information.images.last.uri
45
+ end
46
+
47
+ private
48
+
49
+ def base_uri
50
+ "http://www.tpeweb.co.uk/WebServices/Customer/PODTrackingData.asmx/GetTrackingRecord?#{query_string}"
51
+ end
52
+
53
+ def query_string
54
+ "AccountCode=#{@account_code}&Reference=#{@consignment_no}"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ require 'happymapper'
2
+
3
+ module TuffnellsApi
4
+ class CollectionAddress
5
+ include HappyMapper
6
+
7
+ tag 'ArrayOfTrackingRecord'
8
+ tag 'TrackingRecord'
9
+ tag 'CollectionAddress'
10
+
11
+ element :company_name, String, tag: 'CompanyName'
12
+ element :address_1, String, tag: 'Address1'
13
+ element :address_2, String, tag: 'Address2'
14
+ element :address_3, String, tag: 'Address3'
15
+ element :town, String, tag: 'Town'
16
+ element :postcode, String, tag: 'Postcode'
17
+ element :contact_name, String, tag: 'ContactName'
18
+ element :contact_phone, String, tag: 'ContactTelephone'
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module TuffnellsApi
2
+ class Configuration
3
+ attr_accessor :account_code, :proxy, :read_timeout
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'happymapper'
2
+
3
+ module TuffnellsApi
4
+ class ConsignmentInformation
5
+ include HappyMapper
6
+
7
+ tag 'ArrayOfTrackingRecord'
8
+ tag 'TrackingRecord'
9
+ tag 'ConsignmentInformation'
10
+
11
+ element :pieces, Integer, tag: 'Pieces'
12
+ element :pallets, Integer, tag: 'Pallets'
13
+ element :weight, Integer, tag: 'Weight'
14
+ element :service, String, tag: 'Service'
15
+ element :delivery_date, String, tag: 'DeliveryDate'
16
+ element :items_delivered, Integer, tag: 'ItemsDelivered'
17
+ element :consignment_ref, String, tag: 'ConsignmentRef'
18
+ element :special_instructions, String, tag: 'SpecialInstructions'
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'happymapper'
2
+
3
+ module TuffnellsApi
4
+ class DeliveryAddress
5
+ include HappyMapper
6
+
7
+ tag 'ArrayOfTrackingRecord'
8
+ tag 'TrackingRecord'
9
+ tag 'DeliveryAddress'
10
+
11
+ element :company_name, String, tag: 'CompanyName'
12
+ element :address_1, String, tag: 'Address1'
13
+ element :address_2, String, tag: 'Address2'
14
+ element :address_3, String, tag: 'Address3'
15
+ element :town, String, tag: 'Town'
16
+ element :postcode, String, tag: 'Postcode'
17
+ element :contact_name, String, tag: 'ContactName'
18
+ element :contact_phone, String, tag: 'ContactTelephone'
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module TuffnellsApi
2
+ class Error < StandardError; end
3
+ class NoAccessPermitted < Error; end
4
+ end
@@ -0,0 +1,12 @@
1
+ require 'happymapper'
2
+ require 'tuffnells_api/pod_image'
3
+
4
+ module TuffnellsApi
5
+ class ImageInformation
6
+ include HappyMapper
7
+
8
+ tag 'ImageInformation'
9
+
10
+ has_many :images, TuffnellsApi::PodImage
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ require 'happymapper'
2
+
3
+ module TuffnellsApi
4
+ class Movement
5
+ include HappyMapper
6
+
7
+ tag 'Movement'
8
+
9
+ element :movement_date, String, tag: 'MovementDate'
10
+ element :movement_time, String, tag: 'MovementTime'
11
+ element :description, String, tag: 'Description'
12
+ element :depot, String, tag: 'DeliveryDepot'
13
+ element :round, String, tag: 'Round'
14
+ element :delivery_date, String, tag: 'DeliveryDate'
15
+ element :packages_received, String, tag: 'PackagesReceived'
16
+ element :packaged_delivered, String, tag: 'PackagedDelivered'
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'happymapper'
2
+ require 'tuffnells_api/movement'
3
+
4
+ module TuffnellsApi
5
+ class MovementInformation
6
+ include HappyMapper
7
+
8
+ tag 'ArrayOfTrackingRecord'
9
+ tag 'TrackingRecord'
10
+ tag 'MovementInformation'
11
+
12
+ has_many :movements, TuffnellsApi::Movement
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'happymapper'
2
+
3
+ module TuffnellsApi
4
+ class PodImage
5
+ include HappyMapper
6
+
7
+ tag 'PODImage'
8
+
9
+ element :uri, String, tag: 'URL'
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'happymapper'
2
+
3
+ module TuffnellsApi
4
+ class Scan
5
+ include HappyMapper
6
+
7
+ tag 'Scan'
8
+
9
+ element :piece_id, Integer, tag: 'PieceID'
10
+ element :description, String, tag: 'Description'
11
+ element :depot, String, tag: 'Depot'
12
+ element :date, String, tag: 'ScanDate'
13
+ element :time, String, tag: 'ScanTime'
14
+ element :scanned_by, String, tag: 'ScannedBy'
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require 'happymapper'
2
+ require 'tuffnells_api/scan'
3
+
4
+ module TuffnellsApi
5
+ class ScanInformation
6
+ include HappyMapper
7
+
8
+ tag 'ScanInformation'
9
+
10
+ has_many :scans, TuffnellsApi::Scan
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'happymapper'
2
+
3
+ module TuffnellsApi
4
+ class TimedDelivery
5
+ include HappyMapper
6
+
7
+ tag 'TimedDelivery'
8
+
9
+ element :signature, String, tag: 'Signature'
10
+ element :date, String, tag: 'SignatureDate'
11
+ element :time, String, tag: 'SignatureTime'
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'happymapper'
2
+ require 'tuffnells_api/timed_delivery'
3
+
4
+ module TuffnellsApi
5
+ class TimedInformation
6
+ include HappyMapper
7
+
8
+ tag 'TimedInformation'
9
+
10
+ has_many :deliveries, TuffnellsApi::TimedDelivery
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ require "happymapper"
2
+ require "tuffnells_api/delivery_address"
3
+ require "tuffnells_api/collection_address"
4
+ require "tuffnells_api/consignment_information"
5
+ require "tuffnells_api/movement_information"
6
+ require "tuffnells_api/timed_information"
7
+ require "tuffnells_api/scan_information"
8
+ require "tuffnells_api/image_information"
9
+
10
+ module TuffnellsApi
11
+ class TrackingRecord
12
+ include HappyMapper
13
+
14
+ tag 'ArrayOfTrackingRecord'
15
+ tag 'TrackingRecord'
16
+
17
+ element :authorised, String, tag: 'Authorised'
18
+ element :delivery_address, TuffnellsApi::DeliveryAddress, tag: 'DeliveryAddress'
19
+ element :collection_address, TuffnellsApi::CollectionAddress, tag: 'CollectionAddress'
20
+ element :consignment_information, TuffnellsApi::ConsignmentInformation, tag: 'ConsignmentInformation'
21
+ element :movement_information, TuffnellsApi::MovementInformation, tag: 'MovementInformation'
22
+ element :timed_information, TuffnellsApi::TimedInformation, tag: 'TimedInformation'
23
+ element :scan_information, TuffnellsApi::ScanInformation, tag: 'ScanInformation'
24
+ element :image_information, TuffnellsApi::ImageInformation, tag: 'ImageInformation'
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module TuffnellsApi
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tuffnells_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tuffnells_api"
8
+ spec.version = TuffnellsApi::VERSION
9
+ spec.authors = ["Jamie Barton"]
10
+ spec.email = ["hi_jamie@me.com"]
11
+
12
+ spec.summary = "Access Tuffnells POD via simple Ruby DSL."
13
+ spec.description = "This Rubygem handles tuffnells access and converts XML to JSON."
14
+ spec.homepage = "https://github.com/notrab/tuffnells_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "nokogiri-happymapper", "~> 0.5.9"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tuffnells_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Barton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri-happymapper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.9
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: This Rubygem handles tuffnells access and converts XML to JSON.
70
+ email:
71
+ - hi_jamie@me.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/tuffnells_api.rb
86
+ - lib/tuffnells_api/base.rb
87
+ - lib/tuffnells_api/collection_address.rb
88
+ - lib/tuffnells_api/configuration.rb
89
+ - lib/tuffnells_api/consignment_information.rb
90
+ - lib/tuffnells_api/delivery_address.rb
91
+ - lib/tuffnells_api/errors.rb
92
+ - lib/tuffnells_api/image_information.rb
93
+ - lib/tuffnells_api/movement.rb
94
+ - lib/tuffnells_api/movement_information.rb
95
+ - lib/tuffnells_api/pod_image.rb
96
+ - lib/tuffnells_api/scan.rb
97
+ - lib/tuffnells_api/scan_information.rb
98
+ - lib/tuffnells_api/timed_delivery.rb
99
+ - lib/tuffnells_api/timed_information.rb
100
+ - lib/tuffnells_api/tracking_record.rb
101
+ - lib/tuffnells_api/version.rb
102
+ - tuffnells_api.gemspec
103
+ homepage: https://github.com/notrab/tuffnells_api
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.6.8
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Access Tuffnells POD via simple Ruby DSL.
127
+ test_files: []