xignite 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.
data/CHANGELOG.md ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Nate Clark
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ [![Build Status](https://secure.travis-ci.org/heythisisnate/xignite.png)](http://travis-ci.org/heythisisnate/xignite)
2
+
3
+ ### Xignite Ruby
4
+
5
+ Xignite is a Ruby client library for the [Xignite Web Services API](http://xignite.com)
6
+
7
+ This gem only supports a subset of Xignite's Web Services. **Currently Supported** are all operations under:
8
+
9
+ * [Currencies](http://www.xignite.com/xCurrencies.asmx)
10
+ * [Metals](http://www.xignite.com/xMetals.asmx)
11
+
12
+ ## Installation ##
13
+
14
+ gem install xignite
15
+ require 'xignite'
16
+
17
+ with Bundler, simply:
18
+
19
+ gem 'xignite'
20
+
21
+ ## Basic Usage ##
22
+
23
+ *Xignite Ruby* provides a rubyist's interface to the Xignite API. It constructs a GET or POST request for you, and then parses the response into Array and Hash-like Ruby objects. Reference the Xignite documentation for required parameters and options, and call the appropriate Web Service in one of two ways:
24
+
25
+ # The following two statements do the same thing
26
+ response = Xignite::Metals.get_last_real_time_metal_quote(
27
+ 'Type' => 'XAU', 'Currency' => 'USD'
28
+ )
29
+
30
+ response = Xignite::Metals::GetLastRealTimeMetalQuote(
31
+ 'Type' => 'XAU', 'Currency' => 'USD'
32
+ )
33
+
34
+ The response is a `Xignite::Metals::GetLastRealTimeMetalQuote` object:
35
+
36
+ #<Xignite::Metals::GetLastRealTimeMetalQuote:0x007fbbc3a648f8
37
+ @metal_quote={
38
+ "outcome"=>"Success",
39
+ "identity"=>"Request",
40
+ "delay"=>0.006,
41
+ "symbol"=>"XAUUSDO",
42
+ "type"=>"XAU",
43
+ "currency"=>"USD",
44
+ "date"=>#<Date: 2011-12-09 (4911809/2,0,2299161)>,
45
+ "time"=>2011-12-09 22:59:52 UTC,
46
+ "rate"=>1711.42498779,
47
+ "bid"=>1710.69995117,
48
+ "bid_time"=>2011-12-09
49
+ 22:59:52 UTC,
50
+ "ask"=>1712.15002441,
51
+ "ask_time"=>2011-12-09 22:59:52 UTC
52
+ }>
53
+
54
+ response.metal_quote['ask']
55
+ # => 1712.15002441
56
+
57
+ response.metal_quote['time']
58
+ # => 2011-12-09 22:59:52 UTC
59
+
60
+ ## Configuration ##
61
+
62
+ Xignite.configure do |config|
63
+
64
+ # Configure which HTTP method is used to contact the Xignite service
65
+ # Default: :get, Possible values: [ :get, :post ]
66
+ #
67
+ self.request_method = :get
68
+
69
+ # Configure the endpoint hostname
70
+ # Default: www.xignite.com
71
+ #
72
+ self.endpoint = Xignite::URL
73
+
74
+ # Use HTTPS
75
+ # Default: false
76
+ #
77
+ self.https = true
78
+
79
+ # Set your Xignite username. This automatically adds a 'Header_Username' parameter to all requests
80
+ # Default: nil
81
+ #
82
+ self.username = 'goldbug'
83
+
84
+ end
85
+
86
+ ## Contributing ##
87
+
88
+ To add support for additional web services or features, simply extend from the `Xignite::Service`. Pull requests are encouraged and will be considered promptly.
89
+
90
+ [Issues/Requests](https://github.com/heythisisnate/xignite/issues)
91
+
92
+ ## In the Wild ##
93
+
94
+ Xignite Ruby was originally written and maintained for [GoldBug](http://goldbugapp.com) app. Issue a pull request or let us know if you'd like your site/company link added here.
95
+
96
+ ## Disclaimer ##
97
+
98
+ The author of this software is not affiliated with Xignite and cannot provide support for Xignite products and services.
99
+ Please read the [MIT LICENSE](https://github.com/heythisisnate/xignite/blob/master/LICENSE) before using this software.
@@ -0,0 +1,9 @@
1
+ module Xignite
2
+ class Array < ::Array
3
+ extend Xignite::Helpers
4
+
5
+ def self.build(data, options={})
6
+ new(data)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Xignite
2
+ class Configuration
3
+ attr_accessor :username, :https, :endpoint, :request_method
4
+
5
+ def initialize
6
+ self.endpoint = Xignite::URL
7
+ self.request_method = :get
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ module Xignite
2
+ class Hash < ::Hash
3
+ extend Xignite::Helpers
4
+
5
+ def self.build(data, options={})
6
+ new.tap do |obj|
7
+ data.each do |k, v|
8
+ v = self.build(v, options) if v.class.name == 'Hash'
9
+ obj[underscore(k)] = case v
10
+ when /^[\d,\.]+$/
11
+ v.to_f
12
+ when /^[\d,\/]+$/
13
+ Date.strptime(v, '%m/%d/%Y')
14
+ when /^\d+:\d+:\d+ [APM]{2}$/
15
+ tz = ::TZInfo::Timezone.get(options[:timezone] || 'GMT')
16
+ tz.local_to_utc(Time.strptime("#{data['Date']} #{v}", "#{DATE_FORMAT} #{TIME_FORMAT}"))
17
+ else
18
+ v
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module Xignite
2
+ module Helpers
3
+
4
+ # active_support/inflector/methods.rb
5
+ def underscore(camel_cased_word)
6
+ word = camel_cased_word.to_s.dup
7
+ word.gsub!(/::/, '/')
8
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
9
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
10
+ word.tr!("-", "_")
11
+ word.downcase!
12
+ word
13
+ end
14
+
15
+ # active_support/inflector/methods.rb
16
+ def constantize(camel_cased_word)
17
+ names = camel_cased_word.split('::')
18
+ names.shift if names.empty? || names.first.empty?
19
+
20
+ constant = Object
21
+ names.each do |name|
22
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
23
+ end
24
+ constant
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,82 @@
1
+ module Xignite
2
+ class Service
3
+ extend Xignite::Helpers
4
+ include Xignite::Helpers
5
+
6
+ class << self
7
+ attr_accessor :options
8
+
9
+ def post(options={})
10
+ response = Curl::Easy.http_post(endpoint, *[].tap do |postbody|
11
+ postbody << Curl::PostField.content('Header_Username', Xignite.configuration.username) if Xignite.configuration.username
12
+ options.each do |key, value|
13
+ postbody << Curl::PostField.content(key, value)
14
+ end
15
+ end)
16
+ new(response)
17
+ end
18
+
19
+ def get(options={})
20
+ options = options.merge('Header_Username' => Xignite.configuration.username) if Xignite.configuration.username
21
+ querystring = options.map do |key, value|
22
+ "#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(value)}"
23
+ end.sort * '&'
24
+ response = Curl::Easy.http_get([endpoint, querystring].reject{|s| s == '' }.join('?'))
25
+ new(response)
26
+ end
27
+
28
+ private
29
+
30
+ def endpoint
31
+ names = name.split('::')
32
+ "#{protocol}://#{Xignite.configuration.endpoint}/x#{names[1]}.asmx/#{names[2]}"
33
+ end
34
+
35
+ def protocol
36
+ Xignite.configuration.https ? 'https' : 'http'
37
+ end
38
+
39
+ def operations(ops)
40
+ ops.each do |operation, options|
41
+ underscored_name = underscore(operation)
42
+ const_set(operation, Class.new(self))
43
+ const_get(operation).options = options
44
+ class_eval <<-EOF
45
+ class << self
46
+ def #{underscored_name}(options={})
47
+ #{name}::#{operation}.send(Xignite.configuration.request_method, options)
48
+ end
49
+ alias :#{operation} :#{underscored_name}
50
+ end
51
+ EOF
52
+ end
53
+ end
54
+ end
55
+
56
+ def initialize(curl_response=nil)
57
+ return super if curl_response.nil?
58
+ Crack::XML.parse(curl_response.body_str).each do |klass, data|
59
+ data = weed(data)
60
+ Xignite.const_set(klass, Class.new(Xignite.const_get(data.class.to_s))) unless Xignite.const_defined?(klass)
61
+ instance_variable_set("@#{underscore(klass)}", Xignite.const_get(klass).build(data, self.class.options))
62
+ instance_eval "def #{underscore(klass)} ; @#{underscore(klass)} ; end"
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def weed(data)
69
+ data.reject! { |key| key =~ /\Axmlns/ }
70
+ key = data.keys.first
71
+ array = data[key]
72
+ if data.keys.size == 1 && array.class == ::Array
73
+ Xignite.const_set(key, Class.new(Xignite::Hash)) unless Xignite.const_defined?(key)
74
+ array.map do |hash|
75
+ Xignite.const_get(key).build(hash, self.class.options)
76
+ end
77
+ else
78
+ data
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,44 @@
1
+ module Xignite
2
+ class Currencies < Service
3
+
4
+ operations [
5
+ ['ListCurrencies', {}],
6
+ ['GetRealTimeCrossRate', { :timezone => 'Europe/London' }],
7
+ ['GetRealTimeCrossRateGMT', {}],
8
+ ['GetRealTimeCrossRateAsString', { :timezone => 'Europe/London' }],
9
+ ['GetLatestCrossRate', { :timezone => 'Europe/London' }],
10
+ ['GetLatestCrossRates', { :timezone => 'Europe/London' }],
11
+ ['GetRealTimeCrossRateTable', { :timezone => 'Europe/London' }],
12
+ ['GetRealTimeCrossRateTableAsHTML', {}],
13
+ ['GetRealTimeCrossRateTableWithBidAsk', { :timezone => 'Europe/London' }],
14
+ ['GetHistoricalCrossRate', { :timezone => 'Europe/London' }],
15
+ ['GetHistoricalCrossRates', { :timezone => 'Europe/London' }],
16
+ ['GetHistoricalCrossRatesAsOf', { :timezone => 'Europe/London' }],
17
+ ['GetHistoricalCrossRatesRange', { :timezone => 'Europe/London' }],
18
+ ['GetHistoricalCrossRateBidAsk', { :timezone => 'Europe/London' }],
19
+ ['GetHistoricalCrossRatesBidAsk', { :timezone => 'Europe/London' }],
20
+ ['GetHistoricalCrossRatesBidAskAsOf', { :timezone => 'Europe/London' }],
21
+ ['GetHistoricalCrossRatesBidAskRange', { :timezone => 'Europe/London' }],
22
+ ['GetHistoricalMonthlyCrossRatesRange', { :timezone => 'Europe/London' }],
23
+ ['GetHistoricalCrossRateTable', { :timezone => 'Europe/London' }],
24
+ ['GetHistoricalCrossRateTables', { :timezone => 'Europe/London' }],
25
+ ['GetOfficialCrossRate', { :timezone => 'Europe/London' }],
26
+ ['GetOfficialCrossRates', { :timezone => 'Europe/London' }],
27
+ ['GetAllCrossRatesForACurrency', { :timezone => 'Europe/London' }],
28
+ ['GetCurrencyReport', { :timezone => 'Europe/London' }],
29
+ ['GetAverageHistoricalCrossRate', { :timezone => 'Europe/London' }],
30
+ ['GetAverageHistoricalCrossRates', { :timezone => 'Europe/London' }],
31
+ ['GetRealTimeForwardRate', { :timezone => 'Europe/London' }],
32
+ ['ConvertRealTimeValue', { :timezone => 'Europe/London' }],
33
+ ['ConvertHistoricalValue', { :timezone => 'Europe/London' }],
34
+ ['GetCurrencyChart', {}],
35
+ ['GetCurrencyChartCustom', {}],
36
+ ['GetChartDesign', {}],
37
+ ['GetTicks', {}],
38
+ ['GetTick', {}],
39
+ ['GetHistoricalHighLow', {}],
40
+ ['GetIntradayHighLow', {}],
41
+ ['GetCrossRateChange', {}]
42
+ ]
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ module Xignite
2
+ class Metals < Service
3
+
4
+ operations [
5
+ ['GetLastLondonFixing', {}],
6
+ ['GetLastLondonFixings', {}],
7
+ ['GetHistoricalLondonFixing', {}],
8
+ ['GetHistoricalLondonFixingRange', {}],
9
+ ['GetLastRealTimeMetalQuote', { :timezone => 'Europe/London' }],
10
+ ['GetLastRealTimeExtendedMetalQuote', { :timezone => 'Europe/London' }],
11
+ ['GetLastRealTimeMetalQuotes', { :timezone => 'Europe/London' }],
12
+ ['GetLastRealTimeMetalQuoteGMT', {}],
13
+ ['GetLastRealTimeMetalQuotesGMT', {}],
14
+ ['GetRealTimeMetalQuote', { :timezone => 'Europe/London' }],
15
+ ['GetRealTimeMetalQuotes', { :timezone => 'Europe/London' }],
16
+ ['GetHistoricalSpotPrice', {}],
17
+ ['GetHistoricalSpotPrices', {}],
18
+ ['GetHistoricalSpotPriceRange', {}],
19
+ ['GetDelayedMetalFuture', {}],
20
+ ['GetAllDelayedMetalFutures', {}],
21
+ ['GetHistoricalMetalFuture', {}],
22
+ ['GetHistoricalMetalFutureRange', {}],
23
+ ['GetMetalSpotChart', {}],
24
+ ['GetMetalSpotChartCustom', {}],
25
+ ['GetMetalSpotChartDesign', {}],
26
+ ['GetLondonFixingChart', {}],
27
+ ['GetLondonFixingChartPreset', {}],
28
+ ['GetLondonFixingChartCustom', {}],
29
+ ['GetIntradayMetalFutureChart', {}],
30
+ ['GetIntradayMetalFutureChartCustom', {}],
31
+ ['GetIntradayMetalFutureChartDesign', {}],
32
+ ['GetHistoricalMetalFutureChart', {}],
33
+ ['GetHistoricalFutureMetalChartCustom', {}],
34
+ ['GetHistoricalMetalFutureChartDesign', {}],
35
+ ['GetLastBasePrice', {}],
36
+ ['GetSpotMarketSummary', {}],
37
+ ['GetTicks', {}],
38
+ ['GetTick', {}],
39
+ ['GetTopIndustryHeadlines', {}]
40
+ ]
41
+
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Xignite
2
+ VERSION = '0.1.1'
3
+ end
data/lib/xignite.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'cgi'
2
+ require 'crack'
3
+ require 'curl'
4
+ require 'tzinfo'
5
+ require 'xignite/configuration'
6
+
7
+ module Xignite
8
+ URL = 'www.xignite.com'
9
+ DATE_FORMAT = '%m/%d/%Y'
10
+ TIME_FORMAT = '%I:%M:%S %p'
11
+
12
+ class << self
13
+ def configuration
14
+ @configuration ||= Xignite::Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield configuration if block_given?
19
+ end
20
+ end
21
+ end
22
+
23
+ require 'xignite/helpers'
24
+ require 'xignite/hash'
25
+ require 'xignite/array'
26
+ require 'xignite/service'
27
+ require 'xignite/services/currencies'
28
+ require 'xignite/services/metals'
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xignite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nate Clark
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70117322796120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70117322796120
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70117322795640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70117322795640
36
+ - !ruby/object:Gem::Dependency
37
+ name: curb
38
+ requirement: &70117322789280 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70117322789280
47
+ - !ruby/object:Gem::Dependency
48
+ name: crack
49
+ requirement: &70117322788860 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70117322788860
58
+ - !ruby/object:Gem::Dependency
59
+ name: tzinfo
60
+ requirement: &70117322788400 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70117322788400
69
+ description: Access the Xignite financial data web services with a simple and intuitive
70
+ Ruby library
71
+ email:
72
+ - nate@nateclark.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - lib/xignite/array.rb
78
+ - lib/xignite/configuration.rb
79
+ - lib/xignite/hash.rb
80
+ - lib/xignite/helpers.rb
81
+ - lib/xignite/service.rb
82
+ - lib/xignite/services/currencies.rb
83
+ - lib/xignite/services/metals.rb
84
+ - lib/xignite/version.rb
85
+ - lib/xignite.rb
86
+ - LICENSE
87
+ - README.md
88
+ - CHANGELOG.md
89
+ homepage: http://github.com/heythisisnate/xignite
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: 1.3.6
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.10
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: A Ruby client library for the (Xignite)[http://xignite.com/] web services
113
+ test_files: []