northern911-client 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dcf682473366f0eb08051e0a6ad974cfa82af4c26b157c890ca94e316910b14f
4
+ data.tar.gz: 209eee0e5c0321a7e3c27296dbe76dee694b442bd23caff8d52474a2ac343c51
5
+ SHA512:
6
+ metadata.gz: 9401357e49bdde01fccca9cd116d27b82dcd72e1abcab46ea31c76a4b59d1fc26c6fbb3f68c130d9e87c47fa540052416e59cf807b9300b4836c3c9117676c82
7
+ data.tar.gz: 17cb262972dd0c02cb81dd3f66a26c47057b97c9fda208d264922bbd111ef2190bee209ea2cd4255e2a7259b4cf557fc5a3e6111f4abc0ab170762b9c6f91eea
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at julien.chabanon@modulis.ca. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in Northern911Api.gemspec
4
+ gemspec
5
+
6
+ gem 'savon'
7
+ gem 'pry-byebug'
8
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 CHABANON Julien
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,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'Northern911Api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Northern911Api"
8
+ spec.version = Northern911Api::VERSION
9
+ spec.authors = ["CHABANON Julien"]
10
+ spec.email = ["julien.chabanon@modulis.ca"]
11
+
12
+ spec.summary = %q{A simple API wrapper for Northern911 SOAP API}
13
+ spec.description = %q{This API wrapper is meant to provide a rails friendly configurable api wrapper to access Northern911's SOAP based API using Savon gem.}
14
+ spec.homepage = "http://github.com/modulis/Northern911-API-WRAPPER"
15
+ spec.license = "MIT"
16
+
17
+ spec.name = "northern911-client"
18
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ spec.files = `git ls-files`.split("\n")
20
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_dependency "savon", "~> 2.x"
27
+ end
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Northern911Api
2
+
3
+ A simple Rails friendly API wrapper for Northern911Api's SOAP based API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'Northern911Api', git: 'https://github.com/modulis/Northern911-API-WRAPPER.git'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install Northern911Api
20
+
21
+ ## Usage
22
+ ### Configuration
23
+ First you must configure Northern911Api or you won't be able to make requests.
24
+ ```ruby
25
+ Northern911Api.configure do |config|
26
+ config.vendor_code = '427' # Your api username given to you by Northern911Api
27
+ config.soap_passcode = '#9mB@j3X' # Your secret api key given to you by Northern911Api
28
+ config.sandbox = false # Optional. True by default, you must set it to live manually.
29
+ end
30
+ ```
31
+
32
+ ### Building the client
33
+ You can create a client which will inheret Northern911Api configuration automatically using
34
+ ```ruby
35
+ client = Northern911Api::Client.new
36
+ ```
37
+
38
+ If you would like to change the configuration for a specific client you'll have to do so manually:
39
+ ```ruby
40
+ client.configuration.sandbox = false # sets this client to live mode
41
+ ```
42
+
43
+ ### Some examples
44
+ ```ruby
45
+ client = Northern911Api::Client.new
46
+ client.addor_update_customer(customer: {...}) # see Customer fields below
47
+ client.query_customer({phone_number: '5142842020'})
48
+ client.delete_customer({phone_number: '5142842020'})
49
+ ```
50
+
51
+ ### Customer object should contains
52
+ ```ruby
53
+ :city, :first_name, :last_name, :other_address_info, :phone_number, :realm_id, :postal_code_zip, :province_state, :street_name, :street_number, :suite_apt
54
+ ```
55
+
56
+ ### Available methods
57
+ ```ruby
58
+ [:addor_update_customer, :delete_customer, :query_customer, :get_vendor_dump_url, :verify_customer]
59
+ ```
60
+
61
+ ### Official API doc
62
+ https://addressinfo.northern911.com/soapapidocs/
63
+
64
+
65
+ ### Convenience methods
66
+ Northern911Api has a few convenience methods to use in your code:
67
+ ```ruby
68
+ Northern911Api.configure do |config|
69
+ config.vendor_code = '427' # Your api username given to you by Northern911Api
70
+ config.soap_passcode = '#9mB@j3X' # Your secret api key given to you by Northern911Api
71
+ config.sandbox = false # Optional. True by default, you must set it to live manually.
72
+ end
73
+ ```
74
+
75
+ ## Development
76
+
77
+ You have access to a developer console to use the gem interactively by running `bin/console` from the project directory.
78
+ Please write specs for any additions, and use shared examples when possible.
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/modulis/Northern911-API-WRAPPER.
83
+
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Northern911Api"
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
data/bin/setup ADDED
@@ -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,34 @@
1
+ require "Northern911Api/version"
2
+ require "Northern911Api/configuration"
3
+ require 'Northern911Api/client'
4
+ require 'Northern911Api/model/customer'
5
+
6
+ module Northern911Api
7
+ class << self
8
+ attr_reader :configuration
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.configure
16
+ yield configuration
17
+ end
18
+
19
+ def self.reset
20
+ @configuration = Configuration.new
21
+ end
22
+
23
+ def self.mode
24
+ configuration.sandbox ? :sandbox : :live
25
+ end
26
+
27
+ def self.sandbox?
28
+ configuration.sandbox
29
+ end
30
+
31
+ def self.live?
32
+ !configuration.sandbox
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ require 'savon'
2
+
3
+ module Northern911Api
4
+ class Client
5
+ attr_reader :configuration, :methods
6
+
7
+ def initialize
8
+ @configuration = Northern911Api.configuration
9
+ @savon = savon_client
10
+ @methods = savon_client.operations
11
+ end
12
+
13
+ def method_missing(method_name, *args, &block)
14
+ if methods.include? method_name
15
+ params = {}
16
+ params = (args.first || {}).merge(hash: auth_string)
17
+ params.merge!(vendor_code: configuration.vendor_code)
18
+ # because savon do not support Customer object declared in WSDL as a complex type
19
+ if(method_name == :addor_update_customer)
20
+ raw_xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://schemas.datacontract.org/2004/07/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns2='http://tempuri.org/'><SOAP-ENV:Body><ns2:AddorUpdateCustomer><ns2:customer><ns1:CITY>#{params[:customer][:city]}</ns1:CITY><ns1:ENHANCED_CAPABLE>Y</ns1:ENHANCED_CAPABLE><ns1:FIRST_NAME>#{params[:customer][:first_name]}</ns1:FIRST_NAME><ns1:LAST_DATETIME_MODIFIED xsi:nil='true'/><ns1:LAST_DATETIME_MODIFIED_UNIXTIME xsi:nil='true'/><ns1:LAST_NAME>#{params[:customer][:last_name]}</ns1:LAST_NAME><ns1:OTHER_ADDRESS_INFO>#{params[:customer][:other_address_info]}</ns1:OTHER_ADDRESS_INFO><ns1:PHONE_NUMBER>#{params[:customer][:phone_number]}</ns1:PHONE_NUMBER><ns1:POSTAL_CODE_ZIP>#{params[:customer][:postal_code_zip]}</ns1:POSTAL_CODE_ZIP><ns1:PROVINCE_STATE>#{params[:customer][:province_state]}</ns1:PROVINCE_STATE><ns1:STREET_NAME>#{params[:customer][:street_name]}</ns1:STREET_NAME><ns1:STREET_NUMBER>#{params[:customer][:street_number]}</ns1:STREET_NUMBER><ns1:SUITE_APT>#{params[:customer][:suite_apt]}</ns1:SUITE_APT><ns1:VENDOR_CODE>#{configuration.vendor_code}</ns1:VENDOR_CODE></ns2:customer><ns2:hash>#{params[:hash]}</ns2:hash></ns2:AddorUpdateCustomer></SOAP-ENV:Body></SOAP-ENV:Envelope>"
21
+ @savon.call(method_name, xml: raw_xml)
22
+ elsif(method_name == :query_customer)
23
+ raw_xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://tempuri.org/'><SOAP-ENV:Body><ns1:QueryCustomer><ns1:vendorCode>#{configuration.vendor_code}</ns1:vendorCode><ns1:phoneNumber>#{params[:phone_number]}</ns1:phoneNumber><ns1:hash>#{params[:hash]}</ns1:hash></ns1:QueryCustomer></SOAP-ENV:Body></SOAP-ENV:Envelope>"
24
+ @savon.call(method_name, xml: raw_xml)
25
+ elsif(method_name == :delete_customer)
26
+ raw_xml = "<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns1='http://tempuri.org/'><SOAP-ENV:Body><ns1:DeleteCustomer><ns1:vendorCode>#{configuration.vendor_code}</ns1:vendorCode><ns1:phoneNumber>#{params[:phone_number]}</ns1:phoneNumber><ns1:hash>#{params[:hash]}</ns1:hash></ns1:DeleteCustomer></SOAP-ENV:Body></SOAP-ENV:Envelope>"
27
+ @savon.call(method_name, xml: raw_xml)
28
+ else
29
+ @savon.call(method_name, message: params)
30
+ end
31
+ else
32
+ raise NoMethodError, "#{method_name} is not a valid api endpoint!"
33
+ end
34
+ end
35
+
36
+ private
37
+ def savon_client
38
+ Savon::Client.new wsdl: configuration.wsdl
39
+ end
40
+
41
+ def auth_string
42
+ gmdate = Time.now.strftime('%Y%m%d')
43
+ Digest::MD5.hexdigest(configuration.vendor_code + configuration.soap_passcode + gmdate)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,20 @@
1
+ module Northern911Api
2
+ class Configuration
3
+ attr_accessor :vendor_code, :soap_passcode, :sandbox, :wsdl
4
+
5
+ def initialize(params = {})
6
+ @vendor_code = params[:vendor_code]
7
+ @soap_passcode = params[:soap_passcode]
8
+ @sandbox = params[:sandbox] || true
9
+ @wsdl = @sandbox ? sandbox_url : live_url
10
+ end
11
+
12
+ def sandbox_url
13
+ 'https://soapdev.northern911.com/soap/Service.svc?wsdl'
14
+ end
15
+
16
+ def live_url
17
+ 'https://addressinfo.northern911.com/soap/Service.svc?wsdl'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ require 'savon'
2
+
3
+ module Northern911Api
4
+ class Customer
5
+ attr_reader :configuration
6
+
7
+ extend Savon::Model
8
+ #client wsdl: "https://soapdev.northern911.com/soap/Service.svc?xsd=xsd2"
9
+ #client wsdl: "https://soapdev.northern911.com/soap/Service.svc?wsdl"
10
+
11
+ def initialize(*operations)
12
+ @configuration = Northern911Api.configuration
13
+ self.class.client wsdl: configuration.wsdl
14
+ operations.each { |operation| self.class.operations operation }
15
+ end
16
+
17
+ operations :CITY, :CITY
18
+ operations :ENHANCED_CAPABLE, :ENHANCED_CAPABLE
19
+ operations :FIRST_NAME, :FIRST_NAME
20
+ # operations :authenticate, :find_user
21
+ # operations :authenticate, :find_user
22
+ # operations :authenticate, :find_user
23
+ # operations :authenticate, :find_user
24
+ # operations :authenticate, :find_user
25
+ # operations :authenticate, :find_user
26
+ # operations :authenticate, :find_user
27
+ # operations :authenticate, :find_user
28
+ # operations :authenticate, :find_user
29
+ # operations :authenticate, :find_user
30
+ # operations :authenticate, :find_user
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Northern911Api
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Northern911Api do
4
+ it 'has a version number' do
5
+ expect(Northern911Api::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'Northern911Api'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: northern911-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - CHABANON Julien
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-10 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: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: savon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.x
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.x
69
+ description: This API wrapper is meant to provide a rails friendly configurable api
70
+ wrapper to access Northern911's SOAP based API using Savon gem.
71
+ email:
72
+ - julien.chabanon@modulis.ca
73
+ executables:
74
+ - console
75
+ - setup
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - Northern911Api.gemspec
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/Northern911Api.rb
91
+ - lib/Northern911Api/client.rb
92
+ - lib/Northern911Api/configuration.rb
93
+ - lib/Northern911Api/model/customer.rb
94
+ - lib/Northern911Api/version.rb
95
+ - spec/Northern911Api_spec.rb
96
+ - spec/spec_helper.rb
97
+ homepage: http://github.com/modulis/Northern911-API-WRAPPER
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.3
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A simple API wrapper for Northern911 SOAP API
120
+ test_files: []