reuters 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +23 -0
  3. data/.rubocop.enabled.yml +23 -0
  4. data/.rubocop.yml +15 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +28 -0
  8. data/CONTRIBUTING.md +37 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.txt +22 -0
  11. data/README.md +209 -0
  12. data/Rakefile +5 -0
  13. data/lib/reuters.rb +98 -0
  14. data/lib/reuters/builder.rb +117 -0
  15. data/lib/reuters/client.rb +12 -0
  16. data/lib/reuters/client/base.rb +132 -0
  17. data/lib/reuters/client/fundamentals.rb +20 -0
  18. data/lib/reuters/client/search.rb +19 -0
  19. data/lib/reuters/client/search/base.rb +26 -0
  20. data/lib/reuters/client/search/equity.rb +64 -0
  21. data/lib/reuters/client/token.rb +101 -0
  22. data/lib/reuters/credentials.rb +79 -0
  23. data/lib/reuters/namespaces.rb +25 -0
  24. data/lib/reuters/namespaces/base.rb +47 -0
  25. data/lib/reuters/namespaces/common.rb +30 -0
  26. data/lib/reuters/namespaces/fundamentals.rb +31 -0
  27. data/lib/reuters/namespaces/search.rb +48 -0
  28. data/lib/reuters/namespaces/search/equity.rb +32 -0
  29. data/lib/reuters/namespaces/token.rb +30 -0
  30. data/lib/reuters/response.rb +32 -0
  31. data/lib/reuters/version.rb +6 -0
  32. data/lib/reuters/wsdls.rb +25 -0
  33. data/lib/reuters/wsdls/base.rb +44 -0
  34. data/lib/reuters/wsdls/fundamentals.rb +21 -0
  35. data/lib/reuters/wsdls/search.rb +13 -0
  36. data/lib/reuters/wsdls/search/equity.rb +25 -0
  37. data/lib/reuters/wsdls/token.rb +22 -0
  38. data/reuters.gemspec +41 -0
  39. data/spec/fixtures/responses/token.xml +11 -0
  40. data/spec/reuters/builder_spec.rb +189 -0
  41. data/spec/reuters/client/fundamentals_spec.rb +11 -0
  42. data/spec/reuters/client/search/equity_spec.rb +46 -0
  43. data/spec/reuters/client/token_spec.rb +91 -0
  44. data/spec/reuters/client_spec.rb +0 -0
  45. data/spec/reuters/credentials_spec.rb +68 -0
  46. data/spec/reuters/namespaces/common_spec.rb +5 -0
  47. data/spec/reuters/namespaces/fundamentals_spec.rb +5 -0
  48. data/spec/reuters/namespaces/search/equity_spec.rb +5 -0
  49. data/spec/reuters/namespaces/search_spec.rb +31 -0
  50. data/spec/reuters/namespaces/token_spec.rb +5 -0
  51. data/spec/reuters/namespaces_spec.rb +31 -0
  52. data/spec/reuters/response_spec.rb +54 -0
  53. data/spec/reuters/version_spec.rb +9 -0
  54. data/spec/reuters/wsdls/fundamentals_spec.rb +5 -0
  55. data/spec/reuters/wsdls/search/equity_spec.rb +5 -0
  56. data/spec/reuters/wsdls/token_spec.rb +5 -0
  57. data/spec/reuters/wsdls_spec.rb +31 -0
  58. data/spec/reuters_spec.rb +10 -0
  59. data/spec/spec_helper.rb +17 -0
  60. data/spec/support/client/search_shared.rb +5 -0
  61. data/spec/support/client_shared.rb +70 -0
  62. data/spec/support/configurable_shared.rb +9 -0
  63. data/spec/support/namespaces_actions_shared.rb +36 -0
  64. data/spec/support/namespaces_shared.rb +42 -0
  65. data/spec/support/wsdls_actions_shared.rb +36 -0
  66. data/spec/support/wsdls_shared.rb +53 -0
  67. metadata +333 -0
@@ -0,0 +1,79 @@
1
+ module Reuters
2
+
3
+ # The {Credentials} module handles storing the
4
+ # configured credentials for the {Reuters} gem.
5
+ #
6
+ # @example Configuring credentials.
7
+ # Reuters.configure do |config|
8
+ # config.credentials do |login|
9
+ # # Set username
10
+ # login.username = "my_username"
11
+ # # Set my password
12
+ # login.password = "my_super_secret_password"
13
+ # # Set application ID
14
+ # login.application_id = "application_id"
15
+ # end
16
+ # end
17
+ module Credentials
18
+
19
+ # @!attribute username
20
+ # @!scope class
21
+ # The username to use to authenticate against the
22
+ # Reuter's API with.
23
+ # @return [String, Nil] The configured username, or nil if
24
+ # none is set.
25
+
26
+ # @!attribute password
27
+ # @!scope class
28
+ # The password to use to authenticate against the
29
+ # Reuter's API with.
30
+ # @return [String, Nil] The configured password, or nil if
31
+ # none is set.
32
+
33
+ # @!attribute app_id
34
+ # @!scope class
35
+ # The application ID to use for all requests to the
36
+ # Reuter's API.
37
+ # @return [String, Nil] The configured appication ID, or nil if
38
+ # none is set.
39
+
40
+ mattr_accessor :username
41
+ self.username = nil
42
+
43
+ mattr_accessor :password
44
+ self.password = nil
45
+
46
+ mattr_accessor :app_id
47
+ self.app_id = nil
48
+
49
+ # Yields the configured credentials to connect to the
50
+ # Reuter's API with.
51
+ #
52
+ # @yield [username, password, app_id] Yields authentication information.
53
+ #
54
+ # @yieldparam [String, Nil] username configured, or nil if one is not set.
55
+ # @yieldparam [String, Nil] password configured, or nil if one is not set.
56
+ # @yieldparam [String, Nil] app_id configured, or nil if one is not set.
57
+ def self.details
58
+ yield @@username, @@password, @@app_id
59
+ end
60
+
61
+ # Returns credentials that have been configured as a Hash.
62
+ #
63
+ # @return [Hash] the credentials that have been configured.
64
+ def self.to_h
65
+ { username: username, password: password, app_id: app_id }
66
+ end
67
+
68
+ # Enables credentials to be configured by passing in
69
+ # itself as a block which enables static variables to
70
+ # be set.
71
+ #
72
+ # @yield [config] The credentials to be configured.
73
+ def self.configure
74
+ yield self
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,25 @@
1
+ require 'reuters/namespaces/base'
2
+ require 'reuters/namespaces/token'
3
+ require 'reuters/namespaces/common'
4
+ require 'reuters/namespaces/fundamentals'
5
+ require 'reuters/namespaces/search'
6
+
7
+ module Reuters
8
+ # The {Namespaces} module contains sets of endpoints that
9
+ # are used by Reuters in their internal API. Different
10
+ # Namespaces are used by various clients to gain access
11
+ # to data via API Calls to these namespaced endpoints.
12
+ module Namespaces
13
+
14
+ # Configure a Namespaces stored configurations.
15
+ #
16
+ # @note The passed in namespace is converted to a string
17
+ # and capitalized. It should be in the correct form.
18
+ #
19
+ # @param [Symbol] namespace to configure endpoints for.
20
+ def self.configure(namespace, &block)
21
+ const_get(namespace.to_s).configure(&block)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ module Reuters
2
+ module Namespaces
3
+ # The Base Namespace module is not meant to be directly
4
+ # used as it does not provided any Namespace definitions.
5
+ # Instead, it is included inside other Namespace modules as
6
+ # it provides useful helpers.
7
+ module Base
8
+
9
+ # Class based methods that are set in every
10
+ # module that includes this base module.
11
+ module ClassMethods
12
+
13
+ # Represents the fully resolved namespace endpoint
14
+ # for the Namespace module that has included this
15
+ # class method.
16
+ #
17
+ # @note The returned string is prefixed with the configured
18
+ # #namespaces_endpoint.
19
+ #
20
+ # @return [String] the fully resolved namespace endpoint.
21
+ def endpoint
22
+ "#{Reuters.namespaces_endpoint}/#{year}/#{month}/#{day}/webservices/rkd/#{name}"
23
+ end
24
+
25
+ # Enables this namespace to be configured by passing in
26
+ # itself as a block which enables static variables to
27
+ # be set.
28
+ #
29
+ # @yield [config] The namespace to be configured.
30
+ def configure
31
+ yield self
32
+ end
33
+
34
+ end
35
+
36
+ # @!parse extend ClassMethods
37
+ extend ClassMethods
38
+
39
+ # Extend the including class with the defined
40
+ # class methods.
41
+ def self.included(klass)
42
+ klass.extend(ClassMethods)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ module Reuters
2
+ module Namespaces
3
+ # Common namespaces are used in most API Calls and represent
4
+ # the common set of Namespaces shared amongst most Reuters
5
+ # API requests.
6
+ module Common
7
+
8
+ # @!parse include Base
9
+
10
+ include Base
11
+
12
+ # Year for the Common endpoint.
13
+ mattr_accessor :year
14
+ self.year = '2006'
15
+
16
+ # Month for the Common endpoint.
17
+ mattr_accessor :month
18
+ self.month = '05'
19
+
20
+ # Day for the Common endpoint.
21
+ mattr_accessor :day
22
+ self.day = '01'
23
+
24
+ # Name for the Common endpoint.
25
+ mattr_accessor :name
26
+ self.name = 'Common_1'
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ module Reuters
2
+ module Namespaces
3
+ # The Fundamentals namespace can be used for ascertain
4
+ # important information about companies appearing on the
5
+ # Reuters API. This Namespace is used by all the accompanying
6
+ # Fundamental Client API calls.
7
+ module Fundamentals
8
+
9
+ # @!parse include Base
10
+
11
+ include Base
12
+
13
+ # Year for the Fundamentals endpoint.
14
+ mattr_accessor :year
15
+ self.year = '2009'
16
+
17
+ # Month for the Fundamentals endpoint.
18
+ mattr_accessor :month
19
+ self.month = '01'
20
+
21
+ # Day for the Fundamentals endpoint.
22
+ mattr_accessor :day
23
+ self.day = '26'
24
+
25
+ # Name for the Fundamentals endpoint.
26
+ mattr_accessor :name
27
+ self.name = 'Fundamentals_1'
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ require 'reuters/namespaces/search/equity'
2
+
3
+ module Reuters
4
+ module Namespaces
5
+ # Represents the base search namespaces. Note that because
6
+ # search is quite a broad namespace inside the Reuters api,
7
+ # it is better to use a more specific namespace such as
8
+ # {Reuters::Namespaces::Search::Equity}.
9
+ module Search
10
+
11
+ # @!parse include Base
12
+
13
+ include Base
14
+
15
+ # Year for the Search Equity endpoint.
16
+ mattr_accessor :year
17
+ self.year = '2006'
18
+
19
+ # Month for the Search Equity endpoint.
20
+ mattr_accessor :month
21
+ self.month = '05'
22
+
23
+ # Day for the Search Equity endpoint.
24
+ mattr_accessor :day
25
+ self.day = '01'
26
+
27
+ # Name for the Search Equity endpoint.
28
+ mattr_accessor :name
29
+ self.name = 'Search'
30
+
31
+ # Define a custom name or endpoint that Reuters uses
32
+ # to define XML Namespaces inside the request body.
33
+ #
34
+ # @example Defining a custom namespace
35
+ # str = Reuters::Namespaces::Search.define(:equity_quote, :query_spec, 1)
36
+ # puts str #=> "http://.../Search/EquityQuote_QuerySpec_1"
37
+ # @param [String] strs to convert into a valid namespace
38
+ #
39
+ # @return [String] A full namespaced endpoint with a underscore
40
+ # separated camelized definition.
41
+ def self.define(*strs)
42
+ str = strs.map { |s| s.to_s.camelize }.join('_')
43
+ "#{endpoint}/#{str}"
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,32 @@
1
+ module Reuters
2
+ module Namespaces
3
+ module Search
4
+ # Represents the Search Equity namespace that can be
5
+ # used to query for information about Company
6
+ # financial information.
7
+ module Equity
8
+
9
+ # @!parse include Base
10
+
11
+ include Base
12
+
13
+ # Year for the Search Equity endpoint.
14
+ mattr_accessor :year
15
+ self.year = '2006'
16
+
17
+ # Month for the Search Equity endpoint.
18
+ mattr_accessor :month
19
+ self.month = '05'
20
+
21
+ # Day for the Search Equity endpoint.
22
+ mattr_accessor :day
23
+ self.day = '01'
24
+
25
+ # Name for the Search Equity endpoint.
26
+ mattr_accessor :name
27
+ self.name = 'Search/EquityQuote_1'
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Reuters
2
+ module Namespaces
3
+ # Represents namespaces used by Reuters in their internal API for
4
+ # managing Access Tokens that are granted when valid credentials
5
+ # are used to authenticate.
6
+ module Token
7
+
8
+ # @!parse include Base
9
+
10
+ include Base
11
+
12
+ # Year for the TokenManagement endpoint.
13
+ mattr_accessor :year
14
+ self.year = '2006'
15
+
16
+ # Month for the TokenManagement endpoint.
17
+ mattr_accessor :month
18
+ self.month = '05'
19
+
20
+ # Day for the TokenManagement endpoint.
21
+ mattr_accessor :day
22
+ self.day = '01'
23
+
24
+ # Name for the TokenManagement endpoint.
25
+ mattr_accessor :name
26
+ self.name = 'TokenManagement_1'
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ module Reuters
2
+ # This class parses Savon response bodies into more practical
3
+ # accessible objects, by using a recursive strategy for parsing
4
+ # the content.
5
+ #
6
+ # @note All attributes for XML elements can be accessed via the
7
+ # attributes accessor.
8
+ class Response < Hash
9
+
10
+ attr_accessor :body, :attributes
11
+
12
+ def initialize(body = {})
13
+ unless body.empty?
14
+ merge! body
15
+ attribs = body.keep_if { |k| k.match(/@/) }
16
+ attribs = Hash[attribs.map { |k, v| [k.to_s.gsub(/@/, '').to_sym, v] }]
17
+ @attributes = self.class.new attribs
18
+ end
19
+ end
20
+
21
+ def method_missing(name)
22
+ if key?(name)
23
+ if (val = self[name]).is_a? String
24
+ val
25
+ else
26
+ self.class.new val
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ # Ruby Gem for interacting with the Thomson Reuters
2
+ # Knowledge Direct API.
3
+ module Reuters
4
+ # Current version of the Reuters gem.
5
+ VERSION = '0.8.1'
6
+ end
@@ -0,0 +1,25 @@
1
+ require 'reuters/wsdls/base'
2
+ require 'reuters/wsdls/token'
3
+ require 'reuters/wsdls/fundamentals'
4
+ require 'reuters/wsdls/search'
5
+
6
+ module Reuters
7
+ # The {Wsdls} module contains sets of endpoints that
8
+ # are used by Reuters in their internal API. Wsdls describe
9
+ # valid operations that can be carried out through API
10
+ # requests. Each API group should have an accompanying
11
+ # WSDL, as they are used to make {Client} requests.
12
+ module Wsdls
13
+
14
+ # Configure a Wsdls stored configurations.
15
+ #
16
+ # @note The passed in wsdl is converted to a string
17
+ # and capitalized. It should be in the correct form.
18
+ #
19
+ # @param [Symbol] wsdl to configure endpoints for.
20
+ def self.configure(wsdl, &block)
21
+ const_get(wsdl.to_s).configure(&block)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ module Reuters
2
+ module Wsdls
3
+ # The Base WSDL module is not meant to be directly
4
+ # used as it does not provided any WSDL definitions.
5
+ # Instead, it is included inside other WSDL modules as
6
+ # it provides useful helpers.
7
+ module Base
8
+
9
+ # Class based methods that are set in every
10
+ # module that includes this base module.
11
+ module ClassMethods
12
+
13
+ # Returns the fully resolved WSDL endpoint for the
14
+ # including Module.
15
+ #
16
+ # @return [String] the fully resolved wsdl endpoint
17
+ # (including http://...)
18
+ def endpoint
19
+ "#{Reuters.wsdl_endpoint}/#{name}/wsdl/#{method}"
20
+ end
21
+
22
+ # Enables this WSDL to be configured by passing in
23
+ # itself as a block which enables static variables to
24
+ # be set.
25
+ #
26
+ # @yield [config] The WSDL to be configured.
27
+ def configure
28
+ yield self
29
+ end
30
+
31
+ end
32
+
33
+ # @!parse extend ClassMethods
34
+ extend ClassMethods
35
+
36
+ # Extend the including class with the defined
37
+ # class methods.
38
+ def self.included(klass)
39
+ klass.extend(ClassMethods)
40
+ end
41
+
42
+ end
43
+ end
44
+ end