smartwaiver 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ require 'smartwaiver/agent'
2
+
3
+ module Smartwaiver
4
+
5
+ mattr_accessor :api_key
6
+ mattr_accessor :api_version
7
+ mattr_accessor :base_url
8
+
9
+ # Retrieves waivers from the Smartwaiver API.
10
+ #
11
+ # @param [String] rest_limit Number of records to retrieve, eg "10"
12
+ def self.get_waivers( rest_limit = "10")
13
+ @agent = Agent.new(@@api_key, @@api_version, rest_limit, @@base_url)
14
+ return @agent.request
15
+ end
16
+
17
+ # Retrieves list of waiver types from the Smartwaiver API.
18
+ #
19
+ # @param [String] rest_limit Number of records to retrieve, eg "10"
20
+ def self.get_waivertypes( rest_limit = "10")
21
+ @agent = Agent.new(@@api_key, @@api_version, rest_limit, @@base_url)
22
+ return @agent.request( "&resetapi_listofwaivertypes" )
23
+ end
24
+
25
+ # Download a PDF from Smartwaiver
26
+ #
27
+ # @param [String] pdf_url Encrypted PDF URL provided in the get_waivers method, eg "NTE0OWZjMDdhYzIzMnx8fGNiMjRmZjZlZWMwZjg4YzVkZDBjYzVjMDMwZjI5MzQy"
28
+ def self.download_pdf( pdf_url = "")
29
+ @agent = Agent.new(@@api_key, @@api_version, false, @@base_url)
30
+ return @agent.download_pdf( pdf_url )
31
+ end
32
+
33
+ end
@@ -0,0 +1,50 @@
1
+ require 'mechanize'
2
+
3
+ module Smartwaiver
4
+
5
+ class Agent
6
+
7
+ def initialize(api_key, api_version , rest_limit , base_url )
8
+
9
+ raise ArgumentError, "Missing API Key: Add Smartwaiver.api_key = 'your-key-here' to an initializer" if api_key.blank?
10
+ @api_key = api_key
11
+
12
+ @api_version = api_version || "v2"
13
+ @base_url = base_url || "https://www.smartwaiver.com/api/"
14
+ @rest_limit = rest_limit.to_s || "10"
15
+
16
+ end
17
+
18
+ def request( extra_url = "" )
19
+ final_url = @base_url + @api_version + "/?rest_request=" + @api_key + "&rest_limit=" + @rest_limit + extra_url
20
+ agent = Mechanize.new
21
+ xml = agent.get(final_url).body
22
+ response = Hash.from_xml xml
23
+
24
+ # If there is only a single element in the xml node, Hash.from_xml returns a Hash instead of an Array
25
+ # This section wraps the Hash inside an Array for consistency.
26
+ unless response["xml"].blank? or response["xml"]["participants"].blank?
27
+ if response["xml"]["participants"]["participant"].is_a?(Hash)
28
+ response["xml"]["participants"]["participant"] = [ response["xml"]["participants"]["participant"] ]
29
+ end
30
+ end
31
+
32
+ unless response["xml"].blank? or response["xml"]["waivers"].blank?
33
+ if response["xml"]["waivers"]["waiver"].is_a?(Hash)
34
+ response["xml"]["waivers"]["waiver"] = [ response["xml"]["waivers"]["waiver"] ]
35
+ end
36
+ end
37
+
38
+ return response["xml"]
39
+ end
40
+
41
+ def download_pdf( pdf_url = "" )
42
+ download_url = @base_url + "?rest_request=" + @api_key + "&restapi_viewpdf=" + pdf_url.to_s
43
+ agent = Mechanize.new
44
+ return agent.get(download_url).body
45
+ end
46
+
47
+
48
+ end
49
+
50
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartwaiver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lotus Partners
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Interface for SmartWaiver API
31
+ email: sales@lotuspartners.sg
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/smartwaiver.rb
37
+ - lib/smartwaiver/agent.rb
38
+ homepage: http://rubygems.org/gems/smartwaiver
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.25
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Interface for SmartWaiver API
62
+ test_files: []