lib/mangopay/api/service/e_money.rb in mangopay-v4-4.0.0 vs lib/mangopay/api/service/e_money.rb in mangopay-v4-4.0.1
- old
+ new
@@ -1,42 +1,64 @@
-require_relative '../uri_provider'
-require_relative '../../model/request/currency_request'
-
-module MangoApi
-
- # Provides API method delegates concerning the +EMoney+ entity
- module EMoney
- class << self
- include UriProvider
-
- # Retrieves a user's e-money.
- #
- # @param +user_id+ [String] ID of the user whose e-money to retrieve
- # @param +currency+ [CurrencyIso] currency in which to represent results -
- # defaults to EUR.
- # @return [EMoney] the specified user's EMoney entity object
- def of_user(user_id, currency = nil)
- uri = provide_uri(:get_users_e_money, user_id)
- if currency
- response = HttpClient.get_raw(uri) do |request|
- HttpClient.api_headers.each { |k, v| request.add_field(k, v) }
- request.body = CurrencyRequest.new(currency).jsonify!
- end
- else
- response = HttpClient.get(uri)
- end
- parse response
- end
-
- private
-
- # Parses a JSON-originating hash into the corresponding
- # EMoney entity object.
- #
- # @param +response+ [Hash] JSON-originating data hash
- # @return [EMoney] corresponding EMoney entity object
- def parse(response)
- MangoModel::EMoney.new.dejsonify response
- end
- end
- end
+require_relative '../uri_provider'
+require_relative '../../model/request/currency_request'
+
+module MangoApi
+
+ # Provides API method delegates concerning the +EMoney+ entity
+ module EMoney
+ class << self
+ include UriProvider
+
+ # Retrieves a user's e-money for year.
+ #
+ # @param +user_id+ [String] ID of the user whose e-money to retrieve
+ # @param +year+ [Int] year for which to retrieve e-money
+ # @param +currency+ [CurrencyIso] currency in which to represent results -
+ # defaults to EUR.
+ # @return [EMoney] the specified user's EMoney entity object
+ def of_user_year(user_id, year, currency = nil)
+ uri = provide_uri(:get_users_e_money_year, user_id, year)
+ if currency
+ response = HttpClient.get_raw(uri) do |request|
+ HttpClient.api_headers.each {|k, v| request.add_field(k, v)}
+ request.body = CurrencyRequest.new(currency).jsonify!
+ end
+ else
+ response = HttpClient.get(uri)
+ end
+ parse response
+ end
+
+ # Retrieves a user's e-money for year/month.
+ #
+ # @param +user_id+ [String] ID of the user whose e-money to retrieve
+ # @param +year+ [Int] year for which to retrieve e-money
+ # @param +month+ [Int] month for which to retrieve e-money
+ # @param +currency+ [CurrencyIso] currency in which to represent results -
+ # defaults to EUR.
+ # @return [EMoney] the specified user's EMoney entity object
+ def of_user_month(user_id, year, month, currency = nil)
+ uri = provide_uri(:get_users_e_money_month, user_id, year, month)
+ if currency
+ response = HttpClient.get_raw(uri) do |request|
+ HttpClient.api_headers.each {|k, v| request.add_field(k, v)}
+ request.body = CurrencyRequest.new(currency).jsonify!
+ end
+ else
+ response = HttpClient.get(uri)
+ end
+ parse response
+ end
+
+ private
+
+ # Parses a JSON-originating hash into the corresponding
+ # EMoney entity object.
+ #
+ # @param +response+ [Hash] JSON-originating data hash
+ # @return [EMoney] corresponding EMoney entity object
+ def parse(response)
+ MangoModel::EMoney.new.dejsonify response
+ end
+ end
+ end
end
\ No newline at end of file