Class: CustomersMailCloud::Transaction
- Inherits:
-
Object
- Object
- CustomersMailCloud::Transaction
- Defined in:
- lib/customers_mail_cloud/transaction.rb
Instance Attribute Summary collapse
-
#server_composition ⇒ Object
Returns the value of attribute server_composition.
Instance Method Summary collapse
- #date=(date) ⇒ Object
- #email=(address) ⇒ Object
- #end_date=(date) ⇒ Object
- #hour=(hour) ⇒ Object
-
#initialize(type, client) ⇒ Transaction
constructor
A new instance of Transaction.
- #limit=(limit) ⇒ Object
- #list ⇒ Object
- #minute=(minute) ⇒ Object
- #page=(page) ⇒ Object
- #start_date=(date) ⇒ Object
- #status=(status) ⇒ Object
- #url(action) ⇒ Object
Constructor Details
#initialize(type, client) ⇒ Transaction
Returns a new instance of Transaction.
3 4 5 6 7 8 9 |
# File 'lib/customers_mail_cloud/transaction.rb', line 3 def initialize type, client @client = client @type = type @server_composition = nil @base_url = 'https://api.smtps.jp/transaction/v2/__TYPE__/__ACTION__.json' @params = {} end |
Instance Attribute Details
#server_composition ⇒ Object
Returns the value of attribute server_composition.
11 12 13 |
# File 'lib/customers_mail_cloud/transaction.rb', line 11 def server_composition @server_composition end |
Instance Method Details
#date=(date) ⇒ Object
65 66 67 |
# File 'lib/customers_mail_cloud/transaction.rb', line 65 def date= date @params[:date] = date.strftime('%Y-%m-%d') end |
#email=(address) ⇒ Object
49 50 51 |
# File 'lib/customers_mail_cloud/transaction.rb', line 49 def email= address @params[:email] = address end |
#end_date=(date) ⇒ Object
61 62 63 |
# File 'lib/customers_mail_cloud/transaction.rb', line 61 def end_date= date @params[:end_date] = date.strftime('%Y-%m-%d') end |
#hour=(hour) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/customers_mail_cloud/transaction.rb', line 69 def hour= hour if hour < 0 || hour > 23 raise Error.new('hour allows the range from 0 to 23.') end @params[:hour] = hour end |
#limit=(limit) ⇒ Object
87 88 89 |
# File 'lib/customers_mail_cloud/transaction.rb', line 87 def limit= limit @params[:r] = limit end |
#list ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/customers_mail_cloud/transaction.rb', line 17 def list params = @params params[:api_user] = @client.api_user params[:api_key] = @client.api_key unless @server_composition raise Error.new('Server Composition is required.') end params[:server_composition] = @server_composition headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } uri = URI.parse url('list') req = Net::HTTP::Post.new(uri.path) req.body = params.to_json headers.each do |k, v| req[k] = v end http = Net::HTTP.new uri.host, uri.port http.use_ssl = true response = http.request req if response.code == '200' || response.code == '204' return [] if response.body.nil? return JSON.parse(response.body)[@type] else = JSON.parse(response.body)['errors'].map do |error| "#{error['message']} (#{error['code']})" end.join(" ") raise Error.new end end |
#minute=(minute) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/customers_mail_cloud/transaction.rb', line 76 def minute= minute if minute < 0 || minute > 59 raise Error.new('minute allows the range from 0 to 59.') end @params[:minute] = minute end |
#page=(page) ⇒ Object
83 84 85 |
# File 'lib/customers_mail_cloud/transaction.rb', line 83 def page= page @params[:p] = page end |
#start_date=(date) ⇒ Object
57 58 59 |
# File 'lib/customers_mail_cloud/transaction.rb', line 57 def start_date= date @params[:start_date] = date.strftime('%Y-%m-%d') end |
#status=(status) ⇒ Object
53 54 55 |
# File 'lib/customers_mail_cloud/transaction.rb', line 53 def status= status @params[:status] = status end |
#url(action) ⇒ Object
13 14 15 |
# File 'lib/customers_mail_cloud/transaction.rb', line 13 def url action @base_url.gsub('__TYPE__', @type).gsub('__ACTION__', action) end |