greeve 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -0
  3. data/doc/Greeve.html +5 -5
  4. data/doc/Greeve/API.html +15 -3
  5. data/doc/Greeve/API/CallList.html +466 -0
  6. data/doc/Greeve/Account.html +130 -0
  7. data/doc/Greeve/Account/APIKeyInfo.html +599 -0
  8. data/doc/Greeve/Account/AccountStatus.html +579 -0
  9. data/doc/Greeve/Account/Characters.html +389 -0
  10. data/doc/Greeve/Application.html +428 -0
  11. data/doc/Greeve/Attributable.html +123 -0
  12. data/doc/Greeve/BaseItem.html +240 -210
  13. data/doc/Greeve/Character.html +15 -3
  14. data/doc/Greeve/Character/AccountBalance.html +420 -0
  15. data/doc/Greeve/Character/AssetList.html +480 -0
  16. data/doc/Greeve/Character/Blueprints.html +535 -0
  17. data/doc/Greeve/Character/CalendarEventAttendees.html +461 -0
  18. data/doc/Greeve/Character/CharacterSheet.html +3407 -0
  19. data/doc/Greeve/Character/Clones.html +1700 -0
  20. data/doc/Greeve/Character/ContactList.html +1047 -0
  21. data/doc/Greeve/Character/ContactNotifications.html +446 -0
  22. data/doc/Greeve/Character/ContractBids.html +446 -0
  23. data/doc/Greeve/Character/ContractItems.html +483 -0
  24. data/doc/Greeve/Character/Contracts.html +720 -0
  25. data/doc/Greeve/Character/FacWarStats.html +1075 -0
  26. data/doc/Greeve/Character/IndustryJobs.html +732 -0
  27. data/doc/Greeve/Character/IndustryJobsHistory.html +732 -0
  28. data/doc/Greeve/Character/Locations.html +503 -0
  29. data/doc/Greeve/Character/MailBodies.html +435 -0
  30. data/doc/Greeve/Character/MailMessages.html +485 -0
  31. data/doc/Greeve/Character/MailingLists.html +407 -0
  32. data/doc/Greeve/Character/MarketOrders.html +626 -0
  33. data/doc/Greeve/Character/Medals.html +665 -0
  34. data/doc/Greeve/Character/Notifications.html +459 -0
  35. data/doc/Greeve/Character/PlanetaryColonies.html +524 -0
  36. data/doc/Greeve/Character/PlanetaryLinks.html +444 -0
  37. data/doc/Greeve/Character/PlanetaryPins.html +587 -0
  38. data/doc/Greeve/Character/PlanetaryRoutes.html +548 -0
  39. data/doc/Greeve/Character/Research.html +446 -0
  40. data/doc/Greeve/Character/SkillInTraining.html +865 -0
  41. data/doc/Greeve/Character/SkillQueue.html +472 -0
  42. data/doc/Greeve/Character/Skills.html +516 -0
  43. data/doc/Greeve/Character/Standings.html +650 -0
  44. data/doc/Greeve/Character/UpcomingCalendarEvents.html +511 -0
  45. data/doc/Greeve/Character/WalletJournal.html +658 -0
  46. data/doc/Greeve/Character/WalletTransactions.html +631 -0
  47. data/doc/Greeve/Config.html +315 -0
  48. data/doc/Greeve/Corporation.html +15 -3
  49. data/doc/Greeve/Corporation/AccountBalance.html +324 -0
  50. data/doc/Greeve/Corporation/Contracts.html +700 -0
  51. data/doc/Greeve/Corporation/CorporationSheet.html +1285 -0
  52. data/doc/Greeve/Corporation/IndustryJobs.html +636 -0
  53. data/doc/Greeve/Corporation/IndustryJobsHistory.html +636 -0
  54. data/doc/Greeve/Corporation/Locations.html +452 -0
  55. data/doc/Greeve/Corporation/MarketOrders.html +609 -0
  56. data/doc/Greeve/Corporation/MemberTracking.html +596 -0
  57. data/doc/Greeve/Corporation/Standings.html +554 -0
  58. data/doc/Greeve/Corporation/StarbaseDetail.html +619 -0
  59. data/doc/Greeve/Corporation/StarbaseList.html +389 -0
  60. data/doc/Greeve/Corporation/WalletJournal.html +631 -0
  61. data/doc/Greeve/Corporation/WalletTransactions.html +657 -0
  62. data/doc/Greeve/Eve.html +3 -3
  63. data/doc/Greeve/Eve/AllianceList.html +476 -0
  64. data/doc/Greeve/Eve/CharacterAffiliation.html +491 -0
  65. data/doc/Greeve/Eve/CharacterID.html +413 -0
  66. data/doc/Greeve/Eve/CharacterInfo.html +1705 -52
  67. data/doc/Greeve/Eve/CharacterName.html +414 -0
  68. data/doc/Greeve/Eve/ConquerableStationList.html +402 -0
  69. data/doc/Greeve/Eve/ErrorList.html +311 -0
  70. data/doc/Greeve/Eve/RefTypes.html +312 -0
  71. data/doc/Greeve/Eve/TypeName.html +413 -0
  72. data/doc/Greeve/Helpers.html +130 -0
  73. data/doc/Greeve/Helpers/AddAttribute.html +124 -0
  74. data/doc/Greeve/Helpers/AttributeToHash.html +245 -0
  75. data/doc/Greeve/Helpers/DefineAttributeMethod.html +124 -0
  76. data/doc/Greeve/Helpers/DefineDSLMethods.html +124 -0
  77. data/doc/Greeve/Map.html +15 -3
  78. data/doc/Greeve/Map/FacWarSystems.html +404 -0
  79. data/doc/Greeve/Map/Jumps.html +313 -0
  80. data/doc/Greeve/Map/Kills.html +339 -0
  81. data/doc/Greeve/Map/Sovereignty.html +351 -0
  82. data/doc/Greeve/Namespace.html +586 -0
  83. data/doc/Greeve/ResponseError.html +521 -0
  84. data/doc/Greeve/Row.html +40 -161
  85. data/doc/Greeve/Rowset.html +28 -22
  86. data/doc/Greeve/Server.html +15 -3
  87. data/doc/Greeve/Server/ServerStatus.html +349 -0
  88. data/doc/_index.html +600 -4
  89. data/doc/class_list.html +1 -1
  90. data/doc/file.CONTRIBUTING.html +1 -1
  91. data/doc/file.LICENSE.html +1 -1
  92. data/doc/file.README.html +140 -1
  93. data/doc/index.html +140 -1
  94. data/doc/method_list.html +2024 -32
  95. data/doc/top-level-namespace.html +1 -1
  96. data/lib/greeve.rb +75 -0
  97. data/lib/greeve/account/account_status.rb +22 -0
  98. data/lib/greeve/account/api_key_info.rb +27 -0
  99. data/lib/greeve/account/characters.rb +23 -0
  100. data/lib/greeve/api/call_list.rb +27 -0
  101. data/lib/greeve/base_item.rb +41 -57
  102. data/lib/greeve/character/account_balance.rb +24 -0
  103. data/lib/greeve/character/asset_list.rb +32 -0
  104. data/lib/greeve/character/blueprints.rb +35 -0
  105. data/lib/greeve/character/calendar_event_attendees.rb +33 -0
  106. data/lib/greeve/character/character_sheet.rb +110 -0
  107. data/lib/greeve/character/clones.rb +60 -0
  108. data/lib/greeve/character/contact_list.rb +58 -0
  109. data/lib/greeve/character/contact_notifications.rb +26 -0
  110. data/lib/greeve/character/contract_bids.rb +26 -0
  111. data/lib/greeve/character/contract_items.rb +32 -0
  112. data/lib/greeve/character/contracts.rb +49 -0
  113. data/lib/greeve/character/fac_war_stats.rb +30 -0
  114. data/lib/greeve/character/industry_jobs.rb +48 -0
  115. data/lib/greeve/character/industry_jobs_history.rb +48 -0
  116. data/lib/greeve/character/locations.rb +36 -0
  117. data/lib/greeve/character/mail_bodies.rb +33 -0
  118. data/lib/greeve/character/mail_messages.rb +29 -0
  119. data/lib/greeve/character/mailing_lists.rb +23 -0
  120. data/lib/greeve/character/market_orders.rb +42 -0
  121. data/lib/greeve/character/medals.rb +40 -0
  122. data/lib/greeve/character/notifications.rb +27 -0
  123. data/lib/greeve/character/planetary_colonies.rb +32 -0
  124. data/lib/greeve/character/planetary_links.rb +30 -0
  125. data/lib/greeve/character/planetary_pins.rb +41 -0
  126. data/lib/greeve/character/planetary_routes.rb +38 -0
  127. data/lib/greeve/character/research.rb +26 -0
  128. data/lib/greeve/character/skill_in_training.rb +27 -0
  129. data/lib/greeve/character/skill_queue.rb +28 -0
  130. data/lib/greeve/character/skills.rb +28 -0
  131. data/lib/greeve/character/standings.rb +36 -0
  132. data/lib/greeve/character/upcoming_calendar_events.rb +31 -0
  133. data/lib/greeve/character/wallet_journal.rb +49 -0
  134. data/lib/greeve/character/wallet_transactions.rb +47 -0
  135. data/lib/greeve/config.rb +16 -0
  136. data/lib/greeve/corporation/account_balance.rb +18 -0
  137. data/lib/greeve/corporation/contracts.rb +46 -0
  138. data/lib/greeve/corporation/corporation_sheet.rb +43 -0
  139. data/lib/greeve/corporation/industry_jobs.rb +42 -0
  140. data/lib/greeve/corporation/industry_jobs_history.rb +42 -0
  141. data/lib/greeve/corporation/locations.rb +31 -0
  142. data/lib/greeve/corporation/market_orders.rb +39 -0
  143. data/lib/greeve/corporation/member_tracking.rb +38 -0
  144. data/lib/greeve/corporation/standings.rb +30 -0
  145. data/lib/greeve/corporation/starbase_detail.rb +58 -0
  146. data/lib/greeve/corporation/starbase_list.rb +23 -0
  147. data/lib/greeve/corporation/wallet_journal.rb +48 -0
  148. data/lib/greeve/corporation/wallet_transactions.rb +50 -0
  149. data/lib/greeve/eve/alliance_list.rb +29 -0
  150. data/lib/greeve/eve/character_affiliation.rb +34 -0
  151. data/lib/greeve/eve/character_id.rb +28 -0
  152. data/lib/greeve/eve/character_info.rb +4 -1
  153. data/lib/greeve/eve/character_name.rb +29 -0
  154. data/lib/greeve/eve/conquerable_station_list.rb +24 -0
  155. data/lib/greeve/eve/error_list.rb +17 -0
  156. data/lib/greeve/eve/ref_types.rb +18 -0
  157. data/lib/greeve/eve/type_name.rb +28 -0
  158. data/lib/greeve/helpers/add_attribute.rb +25 -0
  159. data/lib/greeve/helpers/attribute_to_hash.rb +24 -0
  160. data/lib/greeve/helpers/define_dsl_methods.rb +70 -0
  161. data/lib/greeve/map/fac_war_systems.rb +26 -0
  162. data/lib/greeve/map/jumps.rb +19 -0
  163. data/lib/greeve/map/kills.rb +21 -0
  164. data/lib/greeve/map/sovereignty.rb +21 -0
  165. data/lib/greeve/namespace.rb +74 -0
  166. data/lib/greeve/response_error.rb +21 -0
  167. data/lib/greeve/row.rb +11 -33
  168. data/lib/greeve/rowset.rb +6 -15
  169. data/lib/greeve/server/server_status.rb +15 -0
  170. data/lib/greeve/version.rb +1 -1
  171. metadata +165 -2
@@ -0,0 +1,24 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Eve
5
+ # A list of conquerable stations in New Eden.
6
+ #
7
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/eve/eve_conquerablestationlist.html
8
+ class ConquerableStationList < Greeve::BaseItem
9
+ endpoint "eve/ConquerableStationList"
10
+
11
+ rowset :outposts, xpath: "eveapi/result/rowset[@name='outposts']" do
12
+ attribute :station_id, xpath: "@stationID", type: :integer
13
+ attribute :station_name, xpath: "@stationName", type: :string
14
+ attribute :station_type_id, xpath: "@stationTypeID", type: :integer
15
+ attribute :solar_system_id, xpath: "@solarSystemID", type: :integer
16
+ attribute :corporation_id, xpath: "@corporationID", type: :integer
17
+ attribute :corporation_name, xpath: "@corporationName", type: :string
18
+ attribute :x, xpath: "@x", type: :integer
19
+ attribute :y, xpath: "@y", type: :integer
20
+ attribute :z, xpath: "@z", type: :integer
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Eve
5
+ # A list of error codes and text that the API may return.
6
+ #
7
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/eve/eve_errorlist.html
8
+ class ErrorList < Greeve::BaseItem
9
+ endpoint "eve/ErrorList"
10
+
11
+ rowset :errors, xpath: "eveapi/result/rowset[@name='errors']" do
12
+ attribute :error_code, xpath: "@errorCode", type: :integer
13
+ attribute :error_text, xpath: "@errorText", type: :string
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Eve
5
+ # A list of transaction types used in the Corporation::WalletJournal
6
+ # and Character::WalletJournal.
7
+ #
8
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/eve/eve_reftypes.html
9
+ class RefTypes < Greeve::BaseItem
10
+ endpoint "eve/RefTypes"
11
+
12
+ rowset :ref_types, xpath: "eveapi/result/rowset[@name='refTypes']" do
13
+ attribute :ref_type_id, xpath: "@refTypeID", type: :integer
14
+ attribute :ref_type_name, xpath: "@refTypeName", type: :string
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Eve
5
+ # Returns the names associated with a sequence of typeIDs.
6
+ #
7
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/eve/eve_typename.html
8
+ class TypeName < Greeve::BaseItem
9
+ endpoint "eve/TypeName"
10
+
11
+ rowset :types, xpath: "eveapi/result/rowset[@name='types']" do
12
+ attribute :type_id, xpath: "@typeID", type: :integer
13
+ attribute :type_name, xpath: "@typeName", type: :string
14
+ end
15
+
16
+ # @param ids [Array<Integer>, Integer] EVE type IDs
17
+ #
18
+ # @!method initialize(*ids, opts = {})
19
+ def initialize(*ids)
20
+ opts = ids.last.is_a?(Hash) ? ids.pop : {}
21
+
22
+ opts[:query_params] = { "IDs" => ids.join(",") }
23
+
24
+ super(opts)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ module Greeve
2
+ module Helpers
3
+ # Adds a helper method to add an attribute to the attributes hash instance
4
+ # variable.
5
+ module AddAttribute
6
+ private
7
+
8
+ # Add an attribute to the attributes hash instance variable.
9
+ #
10
+ # @param name [String] name of the attribute method
11
+ # @param opts [Hash] option hash passed from the attribute DSL helper method
12
+ def add_attribute(name, opts = {})
13
+ name = name.to_sym
14
+
15
+ raise "Attribute `#{name}` defined more than once" if @attributes[name]
16
+ raise "`:xpath` not specified for `#{name}`" unless opts[:xpath]
17
+
18
+ @attributes[name] = {
19
+ xpath: opts[:xpath],
20
+ type: opts[:type],
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Greeve
2
+ module Helpers
3
+ # Adds the `#to_h` method.
4
+ module AttributeToHash
5
+ # The (private) `#_attributes` method must be implemented for this method
6
+ # to work.
7
+ #
8
+ # @return [Hash] a hash of non-nil attributes
9
+ def to_h
10
+ _attributes
11
+ .keys
12
+ .map { |name|
13
+ value = __send__(name)
14
+ value = value.to_a if value.is_a?(Rowset)
15
+ value = value.to_h if value.is_a?(Namespace)
16
+
17
+ [name, value]
18
+ }
19
+ .to_h
20
+ .reject { |k, v| v.nil? }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,70 @@
1
+ module Greeve
2
+ module Helpers
3
+ # Adds helper methods to define a class or instance method for a given
4
+ # DSL method.
5
+ module DefineDSLMethods
6
+ private
7
+
8
+ # Define a class or instance method for a given attribute.
9
+ #
10
+ # @param scope [:class, :instance] define the attribute names as class or
11
+ # instance methods
12
+ # @param name [String] name of the attribute method
13
+ # @param opts [Hash] option hash passed from the attribute DSL helper method
14
+ def define_attribute_method(scope, name, opts = {})
15
+ method = scope == :instance ? :define_singleton_method : :define_method
16
+
17
+ send(method, name) do
18
+ ivar = instance_variable_get(:"@#{name}")
19
+ return ivar unless ivar.nil?
20
+
21
+ value = @xml_element.locate(opts[:xpath]).first
22
+ value = value.value if value.is_a?(Ox::CData)
23
+
24
+ unless value.nil?
25
+ value =
26
+ case opts[:type]
27
+ when :integer
28
+ value.to_i
29
+ when :integer_array
30
+ value.split(",").map(&:to_i)
31
+ when :numeric
32
+ BigDecimal.new(value)
33
+ when :boolean
34
+ value == "1" || value.downcase == "true"
35
+ when :string
36
+ value.to_s.strip
37
+ when :datetime
38
+ value.empty? ? nil : Time.parse(value + " UTC")
39
+ when :hash
40
+ value.scan(/^(.*?): (.*?)$/).to_h
41
+ end
42
+ end
43
+
44
+ instance_variable_set(:"@#{name}", value)
45
+ end
46
+ end
47
+
48
+ # Define a class or instance method for a given namespace.
49
+ #
50
+ # @param scope [:class, :instance] define the namespace as a class or
51
+ # instance method
52
+ # @param name [String] name of the namespace method
53
+ # @param opts [Hash] option hash passed from the namespace DSL helper method
54
+ def define_namespace_method(scope, name, opts = {}, &block)
55
+ method = scope == :instance ? :define_singleton_method : :define_method
56
+
57
+ send(method, name) do
58
+ ivar = instance_variable_get(:"@#{name}")
59
+ return ivar unless ivar.nil?
60
+
61
+ namespace_element = @xml_element.locate(opts[:xpath]).first
62
+
63
+ namespace = Namespace.new(name.to_sym, namespace_element, &block)
64
+
65
+ instance_variable_set(:"@#{name}", namespace)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Map
5
+ # Returns a list of contestable solar systems and the NPC faction currently
6
+ # occupying them. It should be noted that this only returns a non-zero ID if
7
+ # the occupying faction is not the sovereign faction.
8
+ #
9
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/map/map_facwarsystems.html
10
+ class FacWarSystems < Greeve::BaseItem
11
+ endpoint "map/FacWarSystems"
12
+
13
+ rowset :solar_systems, xpath: "eveapi/result/rowset[@name='solarSystems']" do
14
+ attribute :solar_system_id, xpath: "@solarSystemID", type: :integer
15
+ attribute :solar_system_name, xpath: "@solarSystemName", type: :string
16
+ attribute :occupying_faction_id, xpath: "@occupyingFactionID", type: :integer
17
+ attribute :occupying_faction_name, xpath: "@occupyingFactionName", type: :string
18
+ attribute :owning_faction_id, xpath: "@owningFactionID", type: :integer
19
+ attribute :owning_faction_name, xpath: "@owningFactionName", type: :string
20
+ attribute :contested, xpath: "@contested", type: :boolean
21
+ attribute :victory_points, xpath: "@victoryPoints", type: :integer
22
+ attribute :victory_point_threshold, xpath: "@victoryPointThreshold", type: :integer
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Map
5
+ # Returns the number of jumps in solarsystems within the last hour (doesn’t
6
+ # include wormhole space). Only solar systems where jumps have been made are
7
+ # listed; assume zero in case the system is not listed.
8
+ #
9
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/map/map_jumps.html
10
+ class Jumps < Greeve::BaseItem
11
+ endpoint "map/Jumps"
12
+
13
+ rowset :solar_systems, xpath: "eveapi/result/rowset[@name='solarSystems']" do
14
+ attribute :solar_system_id, xpath: "@solarSystemID", type: :integer
15
+ attribute :ship_jumps, xpath: "@shipJumps", type: :integer
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Map
5
+ # Provides number of ship, pod and NPC kills per solar system within the
6
+ # last hour (doesn’t include wormhole space). Only solar systems where kills
7
+ # have been made are listed; assume zero in case the system is not listed.
8
+ #
9
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/map/map_kills.html
10
+ class Kills < Greeve::BaseItem
11
+ endpoint "map/Kills"
12
+
13
+ rowset :solar_systems, xpath: "eveapi/result/rowset[@name='solarSystems']" do
14
+ attribute :solar_system_id, xpath: "@solarSystemID", type: :integer
15
+ attribute :ship_kills, xpath: "@shipKills", type: :integer
16
+ attribute :faction_kills, xpath: "@factionKills", type: :integer
17
+ attribute :pod_kills, xpath: "@podKills", type: :integer
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../base_item"
2
+
3
+ module Greeve
4
+ module Map
5
+ # Provides sovereignty / ownership information for solar systems in New Eden,
6
+ # excluding wormhole space.
7
+ #
8
+ # @see https://eveonline-third-party-documentation.readthedocs.io/en/latest/xmlapi/map/map_sovereignty.html
9
+ class Sovereignty < Greeve::BaseItem
10
+ endpoint "map/Sovereignty"
11
+
12
+ rowset :solar_systems, xpath: "eveapi/result/rowset[@name='solarSystems']" do
13
+ attribute :solar_system_id, xpath: "@solarSystemID", type: :integer
14
+ attribute :alliance_id, xpath: "@allianceID", type: :integer
15
+ attribute :faction_id, xpath: "@factionID", type: :integer
16
+ attribute :corporation_id, xpath: "@corporationID", type: :integer
17
+ attribute :solar_system_name, xpath: "@solarSystemName", type: :string
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,74 @@
1
+ require_relative "helpers/add_attribute"
2
+ require_relative "helpers/attribute_to_hash"
3
+ require_relative "helpers/define_dsl_methods"
4
+
5
+ module Greeve
6
+ # Contains a group of attributes.
7
+ class Namespace
8
+ include Greeve::Helpers::AddAttribute
9
+ include Greeve::Helpers::DefineDSLMethods
10
+ include Greeve::Helpers::AttributeToHash
11
+
12
+ # @return [Symbol] name of the namespace
13
+ attr_reader :name
14
+
15
+ # @param name [Symbol] name of the namespace
16
+ # @param xml_element [Ox::Element] the xml namespace element for this item
17
+ # @yield a block containing the attribute definitions
18
+ def initialize(name, xml_element, &block)
19
+ @name = name
20
+ @xml_element = xml_element
21
+ @attributes = {}
22
+
23
+ # Load the attribute configuration in the rowset block.
24
+ instance_eval(&block)
25
+
26
+ # Disable the DSL methods since the attributes have been configured.
27
+ define_singleton_method(:attribute) { raise NoMethodError, "private method" }
28
+ define_singleton_method(:namespace) { raise NoMethodError, "private method" }
29
+ end
30
+
31
+ # :nodoc:
32
+ def inspect
33
+ attrs = to_s.lines[1..-1].join
34
+
35
+ "#<#{self.class.name}:#{object_id} name: #{@name}\n#{attrs}\n>"
36
+ end
37
+
38
+ # @return [String] a string representation of the non-nil attributes
39
+ def to_s
40
+ "#{@name}\n" +
41
+ to_h
42
+ .map { |k, v|
43
+ v = v.to_s("F") if v.is_a?(BigDecimal)
44
+ " #{k}: #{v}"
45
+ }
46
+ .join("\n")
47
+ end
48
+
49
+ private
50
+
51
+ # @return [Hash] the hash of attributes for this object
52
+ def _attributes
53
+ @attributes || {}
54
+ end
55
+
56
+ # Map an XML attribute to a Ruby object.
57
+ #
58
+ # @see BaseItem.attribute
59
+ def attribute(name, opts = {})
60
+ add_attribute(name, opts)
61
+ define_attribute_method(:instance, name, opts)
62
+ end
63
+
64
+ # Nest a set of XML attributes inside a namespace.
65
+ #
66
+ # @see BaseItem.namespace
67
+ def namespace(name, opts = {}, &block)
68
+ opts[:type] = :namespace
69
+
70
+ add_attribute(name, opts)
71
+ define_namespace_method(:instance, name, opts, &block)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,21 @@
1
+ module Greeve
2
+ # HTTP response failed.
3
+ class ResponseError < StandardError
4
+ # HTTP error code
5
+ attr_reader :code
6
+ # HTTP error message
7
+ attr_reader :status_message
8
+
9
+ # @option opts [Integer] :code HTTP error code
10
+ # @option opts [String] :status_message HTTP error message
11
+ def initialize(opts = {})
12
+ @code = opts.fetch(:code).to_i
13
+ @status_message = opts.fetch(:status_message).dup.freeze
14
+ end
15
+
16
+ # @return [String] exception error message
17
+ def message
18
+ "#{@code} #{@status_message}"
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,12 @@
1
+ require_relative "helpers/attribute_to_hash"
2
+ require_relative "helpers/define_dsl_methods"
3
+
1
4
  module Greeve
2
5
  # Represents an XML `row` element, contained in a {Rowset}.
3
6
  class Row
7
+ include Greeve::Helpers::AttributeToHash
8
+ include Greeve::Helpers::DefineDSLMethods
9
+
4
10
  # @param xml_element [Ox::Element] the xml row element for this item
5
11
  # @param attributes [Hash] the hash of attribute definitions for this row
6
12
  def initialize(xml_element, attributes)
@@ -8,28 +14,7 @@ module Greeve
8
14
  @attributes = attributes
9
15
 
10
16
  attributes.each do |name, opts|
11
- define_singleton_method(name) do
12
- ivar = instance_variable_get(:"@#{name}")
13
- return ivar unless ivar.nil?
14
-
15
- value = @xml_element.locate(opts[:xpath]).first
16
-
17
- unless value.nil?
18
- value =
19
- case opts[:type]
20
- when :integer
21
- value.to_i
22
- when :numeric
23
- BigDecimal.new(value)
24
- when :string
25
- value.to_s
26
- when :datetime
27
- Time.parse(value + " UTC")
28
- end
29
- end
30
-
31
- instance_variable_set(:"@#{name}", value)
32
- end
17
+ define_attribute_method(:instance, name, opts)
33
18
  end
34
19
  end
35
20
 
@@ -55,18 +40,11 @@ module Greeve
55
40
  .join("\n")
56
41
  end
57
42
 
58
- # @return [Hash] a hash of non-nil attributes
59
- def to_h
60
- @attributes
61
- .keys
62
- .map { |name|
63
- value = __send__(name)
64
- value = value.to_a if value.is_a?(Rowset)
43
+ private
65
44
 
66
- [name, value]
67
- }
68
- .to_h
69
- .reject { |k, v| v.nil? }
45
+ # @return [Hash] the hash of attributes for this object
46
+ def _attributes
47
+ @attributes || {}
70
48
  end
71
49
  end
72
50
  end