starapi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in starapi.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Filipe Chagas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Starapi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'starapi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install starapi
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ require "rails/generators"
2
+ module Starapi
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+
8
+ desc "Creates a Starapi initializer in your application initializers directory."
9
+ def copy_initializer
10
+ template "starapi.rb", "config/initializers/starapi.rb"
11
+ end
12
+
13
+ end # end class
14
+ end #end module
15
+ end # end module
@@ -0,0 +1,6 @@
1
+ Starapi.setup do |config|
2
+ config.namespace = "http://www.example.com/RS/webservices/"
3
+ config.service_url = 'http://www.example.com/READiDataExchange/WSRSDataExchange.asmx'
4
+ config.user = "user"
5
+ config.password = "password"
6
+ end
@@ -0,0 +1,23 @@
1
+ require 'rails'
2
+ require "starapi/version"
3
+ require "starapi/soap_service_facade"
4
+ require "starapi/soap_service_target"
5
+
6
+ module Starapi
7
+ mattr_accessor :namespace
8
+ @@namespace = "http://www.example.com/RS/webservices/"
9
+ mattr_accessor :service_url
10
+ @@service_url = 'http://example/READiDataExchange/WSRSDataExchange.asmx'
11
+ mattr_accessor :user
12
+ @@user = "user"
13
+ mattr_accessor :password
14
+ @@password = "password"
15
+
16
+ class << self
17
+ def setup
18
+ yield self
19
+ end
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,6 @@
1
+ Dir[File.dirname(__FILE__) + "/soap_service_facade/*.rb"].each {|file| load file }
2
+
3
+ module StarApi
4
+ module SoapServiceFacade
5
+ end
6
+ end
@@ -0,0 +1,42 @@
1
+ require 'typhoeus'
2
+ require 'nokogiri'
3
+
4
+ module Starapi
5
+ module SoapServiceFacade
6
+ class Base
7
+ def construct_envelope(&block)
8
+ Nokogiri::XML::Builder.new do |xml|
9
+ xml.Envelope("xmlns:soap12" => "http://www.w3.org/2003/05/soap-envelope",
10
+ "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
11
+ "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema") do
12
+ xml.parent.namespace = xml.parent.namespace_definitions.first
13
+ xml['soap12'].Body(&block)
14
+ end
15
+ end
16
+ end
17
+
18
+ def process_response(response)
19
+ @last_response = response
20
+
21
+ if response.body =~ /soap:Fault/ then
22
+ handle_error(response)
23
+ else
24
+ return response
25
+ end
26
+ end
27
+
28
+ def handle_error(response)
29
+ xml = Nokogiri::XML(response.body)
30
+ xpath = '/soap:Envelope/soap:Body/soap:Fault//soap:Text'
31
+ msg = xml.xpath(xpath).text
32
+
33
+ # TODO: Capture any app-specific exception messages here.
34
+ # For example, if the server returns a Fault when a search
35
+ # has no results, you might rather return an empty array.
36
+
37
+ raise SoapServiceFacade::SoapError.new("Error from server: #{msg}")
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,63 @@
1
+ #################### Xml Structure #########################################################
2
+ #
3
+ # POST /READiDataExchange/WSRSDataExchange.asmx HTTP/1.1
4
+ # Host: 198.61.141.129
5
+ # Content-Type: application/soap+xml; charset=utf-8
6
+ # Content-Length: length
7
+ #
8
+ # <?xml version="1.0" encoding="utf-8"?>
9
+ # <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
10
+ # <soap12:Body>
11
+ # <ExecuteSP xmlns="http://www.opsolve.com/RS/webservices/">
12
+ # <user>string</user>
13
+ # <password>string</password>
14
+ # <spName>string</spName>
15
+ # <paramList>
16
+ # <string>string</string>
17
+ # </paramList>
18
+ # <outputParamList>
19
+ # <string>string</string>
20
+ # </outputParamList>
21
+ # <langCode>string</langCode>
22
+ # </ExecuteSP>
23
+ # </soap12:Body>
24
+ # </soap12:Envelope>
25
+
26
+ module Starapi
27
+ module SoapServiceFacade
28
+ class ExecuteSP < Base
29
+ attr_reader :request_xml, :response
30
+
31
+ def envelope_execute_sp(input_xml)
32
+ envelope = construct_envelope do |xml|
33
+ xml.ExecuteSP("xmlns" => Starapi.namespace) do
34
+ xml.user Starapi.user
35
+ xml.password Starapi.password
36
+ xml.spName "RS_sp_EAI_Output"
37
+ xml.paramList do
38
+ xml.string "input_xml;#{input_xml}"
39
+ end
40
+ xml.outputParamList do
41
+ xml.string "output_xml;8000"
42
+ end
43
+ xml.langCode "en-us"
44
+ end
45
+ end
46
+ end
47
+
48
+ def soap_execute_sp!(input_xml)
49
+ @request_xml = envelope_execute_sp(input_xml).to_xml
50
+ @response = Typhoeus::Request.post(Starapi.service_url,
51
+ :body => @request_xml,
52
+ :headers => {
53
+ 'Content-Type' => "text/xml; charset=utf-8",
54
+ 'Host' => '198.61.141.129',
55
+ 'SOAPAction'=> '"http://www.opsolve.com/RS/webservices/ExecuteSP"',
56
+ 'Content-Length' => @request_xml.length
57
+ })
58
+ @response = process_response(@response)
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ module Starapi
2
+ module SoapServiceFacade
3
+ class SoapError < StandardError
4
+ def initialize(message)
5
+ super(message)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ Dir[File.dirname(__FILE__) + "/soap_service_target/*.rb"].each {|file| load file }
2
+
3
+ module StarApi
4
+ module SoapServiceTarget
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ module Starapi
2
+ module SoapServiceTarget
3
+ class Base
4
+ attr_reader :soap_execute_sp
5
+
6
+ def soap_service_sp
7
+ @soap_execute_sp ||= SoapServiceFacade::ExecuteSP.new
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,92 @@
1
+ #################### Xml Structure #########################################################
2
+ #
3
+ # #### Request ###
4
+ #
5
+ # <ReadiSystem>
6
+ # <proc_type>GU_sp_DR_Price_Quote</proc_type>
7
+ # <entno>7827</entno>
8
+ # <supno>DUKE_OH</supno>
9
+ # <rev_type>R</rev_type>
10
+ # <request_date>2012-12-05</request_date>
11
+ # </ReadiSystem>
12
+ #
13
+ # ### Response ###
14
+ # <READiSystem>
15
+ # <GU_sp_DR_FF_Quote>
16
+ # <entno>0001</entno>
17
+ # <supno>FE_OHED</supno>
18
+ # <offer_desc>Ohio Electric - Residential</offer_desc>
19
+ # <rev_type>R</rev_type>
20
+ # <price_desc>Ohio Res - 1 Yr Fixed - Dec 12</price_desc>
21
+ # <enroll_eff_date>2012-12-01</enroll_eff_date>
22
+ # <enroll_exp_date>2012-12-31</enroll_exp_date>
23
+ # <offer_price>0.0965</offer_price >
24
+ # <price_uom>kWh</price_uom>
25
+ # <price_to_compare >0.0984</price_to_compare>
26
+ # <ptc_message>The Price to Compare for Ohio Electric was derived assuming a 750kWh average monthly consumption. Your actual Price to Compare could vary slightly based on your actual usage.</ptc_message>
27
+ # </GU_sp_DR_FF_Quote>
28
+ # </READiSystem>
29
+
30
+ module Starapi
31
+ module SoapServiceTarget
32
+ class PriceQuote < Base
33
+
34
+ @@PROC_TYPE = "GU_sp_DR_Price_Quote"
35
+
36
+ attr_reader :entno, :supno, :rev_type, :request_date, :request_xml, :last_response
37
+ attr_writer :entno, :supno, :rev_type, :request_date
38
+
39
+ def initialize(entno, supno, rev_type, request_date)
40
+ @entno, @supno, @rev_type, @request_date = entno, supno, rev_type, request_date
41
+ end
42
+
43
+ def construct_xml
44
+ Nokogiri::XML::Builder.new do |xml|
45
+ xml.ReadiSystem do
46
+ xml.proc_type @@PROC_TYPE
47
+ xml.entno @entno
48
+ xml.supno @supno
49
+ xml.rev_type @rev_type
50
+ xml.request_date @request_date
51
+ end
52
+ end
53
+ end
54
+
55
+ def soap_price_quote!
56
+ @request_xml = construct_xml.to_xml
57
+ @last_response = get_target_response soap_service_sp.soap_execute_sp!(@request_xml)
58
+ end
59
+
60
+ def parse_response
61
+ if @last_response.blank?
62
+ raise StandardError.new "Response is not loaded. It looks like the request was not made."
63
+ end
64
+
65
+ xml = Nokogiri::XML(@last_response)
66
+
67
+ parsed_obj = OpenStruct.new
68
+
69
+ parsed_obj.entno = xml.xpath("//entno").text
70
+ parsed_obj.supno = xml.xpath("//supno").text
71
+ parsed_obj.offer_desc = xml.xpath("//offer_desc").text
72
+ parsed_obj.rev_type = xml.xpath("//rev_type").text
73
+ parsed_obj.price_desc = xml.xpath("//price_desc").text
74
+ parsed_obj.enroll_eff_date = xml.xpath("//enroll_eff_date").text
75
+ parsed_obj.enroll_exp_date = xml.xpath("//enroll_exp_date").text
76
+ parsed_obj.offer_price = xml.xpath("//offer_price").text
77
+ parsed_obj.price_uom = xml.xpath("//price_uom").text
78
+ parsed_obj.price_to_compare = xml.xpath("//price_to_compare").text
79
+ parsed_obj.ptc_message = xml.xpath("//ptc_message").text
80
+ parsed_obj
81
+ end
82
+
83
+ private
84
+ def get_target_response(response)
85
+ xml = Nokogiri::XML(response.body)
86
+ xpath = '/soap:Envelope/soap:Body'
87
+ xml.xpath(xpath).text
88
+ end
89
+
90
+ end # end class
91
+ end # end module
92
+ end #end module
@@ -0,0 +1,3 @@
1
+ module Starapi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "starapi/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Filipe Chagas"]
7
+ gem.email = ["filipe@ochagas.com"]
8
+ gem.license = "MIT"
9
+ gem.description = %q{Gem created in order to consume READi System Webservices}
10
+ gem.summary = %q{Gem created in order to consume READi System Webservices}
11
+ gem.homepage = "http://github.com/Quezmedia/quez_starapi"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "starapi"
17
+ gem.require_paths = ["lib", "lib/soap_service_facade", "lib/soap_service_target"]
18
+ gem.version = Starapi::VERSION
19
+
20
+ gem.add_dependency 'typhoeus'
21
+ gem.add_dependency 'nokogiri'
22
+ gem.add_dependency("railties", "~> 3.1")
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: starapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Filipe Chagas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: typhoeus
16
+ requirement: &70302244985180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70302244985180
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70302244984600 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70302244984600
36
+ - !ruby/object:Gem::Dependency
37
+ name: railties
38
+ requirement: &70302245015660 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.1'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70302245015660
47
+ description: Gem created in order to consume READi System Webservices
48
+ email:
49
+ - filipe@ochagas.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/generators/starapi/install_generator.rb
60
+ - lib/generators/templates/starapi.rb
61
+ - lib/starapi.rb
62
+ - lib/starapi/soap_service_facade.rb
63
+ - lib/starapi/soap_service_facade/base.rb
64
+ - lib/starapi/soap_service_facade/execute_sp.rb
65
+ - lib/starapi/soap_service_facade/soap_error.rb
66
+ - lib/starapi/soap_service_target.rb
67
+ - lib/starapi/soap_service_target/base.rb
68
+ - lib/starapi/soap_service_target/price_quote.rb
69
+ - lib/starapi/version.rb
70
+ - starapi.gemspec
71
+ homepage: http://github.com/Quezmedia/quez_starapi
72
+ licenses:
73
+ - MIT
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ - lib/soap_service_facade
79
+ - lib/soap_service_target
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.10
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Gem created in order to consume READi System Webservices
98
+ test_files: []