powa_api 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ .rvmrc
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ coverage
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+ *.yml
16
+
17
+ # YARD artifacts
18
+ .yardoc
19
+ _yardoc
20
+ doc/
21
+
22
+ # Rubymine files
23
+ .idea/
24
+
25
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in powa-api.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ powa-api
2
+ ========
3
+
4
+ Ruby interface to the POWA API
5
+
6
+ [http://developer.powa.com/guide](http://developer.powa.com/guide)
7
+
8
+ Configuration
9
+ -------------
10
+
11
+ ### Yaml example
12
+
13
+ ```yaml
14
+ environment: "sandbox"
15
+ integration_security_key: "KEY-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
16
+ website_authorisation_token: "TOKEN-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
17
+ ```
18
+
19
+ Then
20
+
21
+ ```ruby
22
+ PowaApi.configure_with("path/to/yaml/file")
23
+ ```
24
+
25
+ ### Ruby example
26
+
27
+ ```ruby
28
+ PowaApi.configure(:environment => "sandbox", :integration_security_key => "KEY-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
29
+ :website_authorisation_token => "TOKEN-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
30
+ ```
31
+
32
+ Usage
33
+ -------------
34
+
35
+ ```ruby
36
+ products = PowaApi::ProductService.get_products
37
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,76 @@
1
+ module PowaApi
2
+ class OrderService < PowaService
3
+
4
+ def self.find_updated_orders(updated_from, updated_to = nil)
5
+
6
+ client = Savon.client wsdl
7
+
8
+ response = client.request :get_updated_orders do
9
+ soap.xml do |xml|
10
+ xml.soapenv(:Envelope, namespaces) do |xml|
11
+
12
+ header_block(xml)
13
+
14
+ xml.soapenv(:Body) do |xml|
15
+ xml.urn(:FindUpdatedOrdersRequest) do |xml|
16
+ xml.updatedFrom updated_from.strftime('%FT%T.000')
17
+ xml.updateTo updated_to.strftime('%FT%T.000') if updated_to
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ [response.to_array(:find_updated_orders_response).first[:orders]].flatten.compact
25
+
26
+ end
27
+
28
+ def self.get_order_details(order_number)
29
+
30
+ client = Savon.client wsdl
31
+
32
+ begin
33
+ response = client.request :get_order_details do
34
+ soap.xml do |xml|
35
+ xml.soapenv(:Envelope, namespaces) do |xml|
36
+
37
+ header_block(xml)
38
+
39
+ xml.soapenv(:Body) do |xml|
40
+ xml.urn(:GetOrderDetailsRequest) do |xml|
41
+ xml.orderNumber order_number
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ rescue Savon::SOAP::Fault => e
48
+ return nil if e.message.include?("Order not found")
49
+ raise e.message
50
+ end
51
+
52
+ response.to_array(:get_order_details_response).first
53
+
54
+ end
55
+
56
+ # This method invokes find_updated_orders and then calls get_order_details for each order
57
+ # and returns an array of the results
58
+ def self.get_orders(start_date, end_date)
59
+ orders = []
60
+ order_ids = OrderService.find_updated_orders(start_date, end_date)
61
+
62
+ order_ids.each do |order_id|
63
+ orders << OrderService.get_order_details(order_id)
64
+ end
65
+
66
+ return orders.flatten.compact
67
+ end
68
+
69
+ private
70
+
71
+ def self.wsdl
72
+ base_url + "OrderService?wsdl"
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,54 @@
1
+ module PowaApi
2
+ class PowaService
3
+
4
+ def self.get_publish_info
5
+ client = Savon.client wsdl
6
+
7
+ response = client.request :get_publish_info do
8
+ soap.xml do |xml|
9
+ xml.soapenv(:Envelope, namespaces) do |xml|
10
+
11
+ header_block(xml)
12
+
13
+ xml.soapenv(:Body) do |xml|
14
+ xml.urn(:GetPublishInfoRequest) do |xml|
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ response.to_array(:get_publish_info_response).first
22
+ end
23
+
24
+ protected
25
+
26
+ def self.wsdl
27
+ base_url + "PublishService?wsdl"
28
+ end
29
+
30
+ def self.base_url
31
+ if ::PowaApi.config[:environment] == "production"
32
+ "https://api.powa.com/ws/soap/v2/"
33
+ else
34
+ "https://api.sandbox.powa.com/ws/soap/v2/"
35
+ end
36
+ end
37
+
38
+ def self.header_block(xml)
39
+ xml.soapenv(:Header) do |xml|
40
+ xml.urn(:Credentials) do |xml|
41
+ xml.integrationSecurityKey ::PowaApi.config[:integration_security_key]
42
+ xml.websiteAuthorisationToken ::PowaApi.config[:website_authorisation_token]
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.namespaces
48
+ {
49
+ "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/",
50
+ "xmlns:urn" => "urn:powa:api:PowaAPI"
51
+ }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,106 @@
1
+ module PowaApi
2
+ class ProductService < PowaService
3
+
4
+ def self.get_published_products(publish_token, batch_number = nil)
5
+ client = Savon.client wsdl
6
+
7
+ response = client.request :get_published_products do
8
+ soap.xml do |xml|
9
+ xml.soapenv(:Envelope, namespaces) do |xml|
10
+
11
+ header_block(xml)
12
+
13
+ xml.soapenv(:Body) do |xml|
14
+ xml.urn(:GetPublishedProductsRequest) do |xml|
15
+ xml.publishToken publish_token
16
+ xml.batchNumber batch_number if batch_number
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ [response.to_array(:get_published_products_response).first[:products]].flatten.compact
24
+ end
25
+
26
+ def self.get_published_products_by_sku(*skus)
27
+ client = Savon.client wsdl
28
+
29
+ response = client.request :get_published_products_by_sku do
30
+ soap.xml do |xml|
31
+ xml.soapenv(:Envelope, namespaces) do |xml|
32
+
33
+ header_block(xml)
34
+
35
+ xml.soapenv(:Body) do |xml|
36
+ xml.urn(:GetProductsBySkuRequest) do |xml|
37
+ xml.skuList do |xml|
38
+ skus.each do |sku|
39
+ xml.sku sku
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ [response.to_array(:get_products_by_sku_response).first[:product]].flatten.compact
49
+ end
50
+
51
+ def self.get_products(batch_number = nil)
52
+
53
+ client = Savon.client wsdl
54
+
55
+ response = client.request :get_products do
56
+ soap.xml do |xml|
57
+ xml.soapenv(:Envelope, namespaces) do |xml|
58
+
59
+ header_block(xml)
60
+
61
+ xml.soapenv(:Body) do |xml|
62
+ xml.urn(:GetProductsRequest) do |xml|
63
+ xml.batchNumber batch_number if batch_number
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ [response.to_array(:get_products_response).first[:product]].flatten.compact
71
+
72
+ end
73
+
74
+ def self.get_products_by_sku(*skus)
75
+ client = Savon.client wsdl
76
+
77
+ response = client.request :get_products_by_sku do
78
+ soap.xml do |xml|
79
+ xml.soapenv(:Envelope, namespaces) do |xml|
80
+
81
+ header_block(xml)
82
+
83
+ xml.soapenv(:Body) do |xml|
84
+ xml.urn(:GetProductsBySkuRequest) do |xml|
85
+ xml.skuList do |xml|
86
+ skus.each do |sku|
87
+ xml.sku sku
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ [response.to_array(:get_products_by_sku_response).first[:product]].flatten.compact
97
+ end
98
+
99
+ private
100
+
101
+ def self.wsdl
102
+ base_url + "ProductService?wsdl"
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ module PowaApi
2
+ VERSION = "0.0.3"
3
+ end
data/lib/powa_api.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'savon'
2
+ require 'yaml'
3
+ require 'powa_api/version'
4
+ require 'powa_api/powa_service'
5
+ require 'powa_api/product_service'
6
+ require 'powa_api/order_service'
7
+
8
+ module PowaApi
9
+
10
+ extend self
11
+
12
+ @config = {
13
+ :integration_security_key => "KEY-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
14
+ :website_authorisation_token => "TOKEN-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
15
+ :environment => "sandbox"
16
+ }
17
+
18
+ @valid_config_keys = @config.keys
19
+
20
+ def self.configure(opts = {})
21
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
22
+ end
23
+
24
+ def self.configure_with(path_to_yaml_file)
25
+ begin
26
+ config = YAML::load(IO.read(path_to_yaml_file))
27
+ rescue Errno::ENOENT
28
+ log(:warning, "YAML configuration file couldn't be found. Using defaults."); return
29
+ rescue Psych::SyntaxError
30
+ log(:warning, "YAML configuration file contains invalid syntax. Using defaults."); return
31
+ end
32
+
33
+ configure(config)
34
+ end
35
+
36
+ def self.config
37
+ @config
38
+ end
39
+
40
+ end
data/powa_api.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+ require 'powa_api/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "powa_api"
7
+ s.version = PowaApi::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["jzw", "mikelarkin"]
10
+ s.email = []
11
+ s.homepage = "http://github.com/mikelarkin/powa_api"
12
+ s.summary = "Implementation of the Powa API"
13
+ s.description = "Implementation of the Powa API"
14
+
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+ s.rubyforge_project = "powa_api"
17
+
18
+ s.add_development_dependency "bundler", ">= 1.0.0.rc.5"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
22
+ s.require_path = 'lib'
23
+ s.add_dependency 'savon'
24
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: powa_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jzw
9
+ - mikelarkin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-11-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: &70218966339480 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0.rc.5
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70218966339480
26
+ - !ruby/object:Gem::Dependency
27
+ name: savon
28
+ requirement: &70218966338120 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70218966338120
37
+ description: Implementation of the Powa API
38
+ email: []
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - lib/powa_api.rb
48
+ - lib/powa_api/order_service.rb
49
+ - lib/powa_api/powa_service.rb
50
+ - lib/powa_api/product_service.rb
51
+ - lib/powa_api/version.rb
52
+ - powa_api.gemspec
53
+ homepage: http://github.com/mikelarkin/powa_api
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.6
71
+ requirements: []
72
+ rubyforge_project: powa_api
73
+ rubygems_version: 1.8.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Implementation of the Powa API
77
+ test_files: []