Class: EME::Subscription
- Inherits:
-
APIConsumer
- Object
- APIConsumer
- EME::Subscription
- Defined in:
- lib/eme/subscription.rb
Class Method Summary collapse
- .add_days(sub_id, days, notes = nil, additional_info = nil, conn = connection, opts = {}, reload = false) ⇒ Object
- .add_days_with_subscription_creation(ma_id, game_account_id, game_id, days, request_opts = {}, conn = connection, opts = {}, reload = false) ⇒ Object
- .all(page = 1, count = 100, conn = connection, opts = {}, reload = false) ⇒ Object
- .cancel(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .clear_cache_for_account(account) ⇒ Object
- .clear_cache_for_subscription(sub_id) ⇒ Object
- .create(ma_id, game_account_id, game_id, request_opts = {}, conn = connection, opts = {}, reload = false) ⇒ Object
- .delete(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .delete_price_override(master_account_id, game_account_id, game_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .events(sub_id, game_account_id, master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .events_for_sub(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .fetch(subscription_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .fetch_active(master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .fetch_active_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .fetch_all(master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .fetch_all_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .fetch_price_overrides_by_game_account_id(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .price_override_logs(game_account_id, master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .remove_days(sub_id, days, notes = nil, additional_info = nil, conn = connection, opts = {}, reload = false) ⇒ Object
- .revive(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .subscription_info_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .update(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
- .update_renew_price_by_game_account(game_account_id, price, conn = connection, opts = {}, reload = false) ⇒ Object
- .upsert_price_override(master_account_id, game_account_id, game_id, override_price, conn = connection, opts = {}, reload = false) ⇒ Object
Class Method Details
.add_days(sub_id, days, notes = nil, additional_info = nil, conn = connection, opts = {}, reload = false) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/eme/subscription.rb', line 109 def self.add_days(sub_id, days, notes = nil, additional_info = nil, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post opts[:body] = {:days => days, :notes => notes, :additional_info => additional_info}.to_json results = do_request("/subscriptions/#{sub_id}/add_days", conn, opts) clear_cache_for_subscription(sub_id) return results end |
.add_days_with_subscription_creation(ma_id, game_account_id, game_id, days, request_opts = {}, conn = connection, opts = {}, reload = false) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/eme/subscription.rb', line 119 def self.add_days_with_subscription_creation(ma_id, game_account_id, game_id, days, request_opts = {}, conn = connection, opts ={}, reload = false) #optional params: :subscription_kind_name, :notes, :addition_info json = request_opts json[:master_account_id] = ma_id json[:game_account_id] = game_account_id json[:game_id] = game_id json[:days] = days json[:subscription_kind_name] = "30dayelite" if json[:subscription_kind_name].nil? opts = opts_work(opts) # no cache opts[:reload] ||= reload opts[:method] = :post opts[:body] = json.to_json results = do_request("/subscriptions/add_days", conn, opts) # erase cache here clear_cache_for_account(ma_id) if results['subscription'] && results['subscription']['id'] clear_cache_for_subscription(results['subscription']['id']) end return results end |
.all(page = 1, count = 100, conn = connection, opts = {}, reload = false) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/eme/subscription.rb', line 5 def self.all(page = 1, count = 100, conn = connection, opts = {}, reload = false) opts = opts_work(opts) opts[:ttl] ||= 10 opts[:reverse] ||= false opts[:orderby] ||= "id" opts[:reload] ||= reload return do_request("/subscriptions?from=#{(page-1)*count}&count=#{count}&orderby=#{opts[:orderby]}&reverse=#{opts[:reverse]}", conn, opts) end |
.cancel(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/eme/subscription.rb', line 67 def self.cancel(sub_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post results = do_request("/subscriptions/#{sub_id}/cancel", conn, opts) clear_cache_for_subscription(sub_id) return results end |
.clear_cache_for_account(account) ⇒ Object
222 223 224 225 226 |
# File 'lib/eme/subscription.rb', line 222 def self.clear_cache_for_account(account) cache.clear("active-m-account-sub-#{account}") cache.clear("all-m-account-sub-#{account}") return true end |
.clear_cache_for_subscription(sub_id) ⇒ Object
228 229 230 231 |
# File 'lib/eme/subscription.rb', line 228 def self.clear_cache_for_subscription(sub_id) cache.clear("sub-#{sub_id}") return true end |
.create(ma_id, game_account_id, game_id, request_opts = {}, conn = connection, opts = {}, reload = false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/eme/subscription.rb', line 48 def self.create(ma_id, game_account_id, game_id, request_opts = {}, conn = connection, opts ={}, reload = false) #optional params: :recurring, :started_at, :ended_at, :next_delivery_at, :next_payment_at, :subscription_kind_id json = request_opts json[:master_account_id] = ma_id json[:start] = true if json[:start].nil? json[:game_account_id] = game_account_id json[:game_id] = game_id json[:subscription_kind_name] = "30dayelite" if json[:subscription_kind_name].nil? opts = opts_work(opts) # no cache opts[:reload] ||= reload opts[:method] = :post opts[:body] = json.to_json results = do_request("/subscriptions", conn, opts) # erase cache here clear_cache_for_account(ma_id) return results end |
.delete(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/eme/subscription.rb', line 85 def self.delete(sub_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :delete results = do_request("/subscriptions/#{sub_id}", conn, opts) clear_cache_for_subscription(sub_id) return results end |
.delete_price_override(master_account_id, game_account_id, game_id, conn = connection, opts = {}, reload = false) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/eme/subscription.rb', line 191 def self.delete_price_override(master_account_id, game_account_id, game_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post body = {} body[:master_account_id] = master_account_id if master_account_id body[:game_account_id] = game_account_id if game_account_id body[:game_id] = game_id if game_id opts[:body] = body.to_json return do_request("/subscription_price_overrides/delete", conn, opts) end |
.events(sub_id, game_account_id, master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/eme/subscription.rb', line 160 def self.events(sub_id, game_account_id, master_account_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:count] ||= 100 opts[:reverse] ||= false opts[:orderby] ||= "id" url = "/subscription_events?orderby=#{opts[:orderby]}&reverse=#{opts[:reverse]}&count=#{opts[:count]}" url += "&subscription_id=#{sub_id}" if sub_id url += "&game_account_id=#{game_account_id}" if game_account_id url += "&master_account_id=#{master_account_id}" if master_account_id return do_request(url, conn, opts) end |
.events_for_sub(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/eme/subscription.rb', line 151 def self.events_for_sub(sub_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:count] ||= 100 opts[:reverse] ||= false opts[:orderby] ||= "id" return do_request("/subscription_events?orderby=#{opts[:orderby]}&reverse=#{opts[:reverse]}&count=#{opts[:count]}&subscription_id=#{sub_id}", conn, opts) end |
.fetch(subscription_id, conn = connection, opts = {}, reload = false) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/eme/subscription.rb', line 41 def self.fetch(subscription_id, conn = connection, opts = {}, reload = false) opts = opts_work(opts, "sub-#{subscription_id}") opts[:reload] ||= reload opts[:ttl] ||= 10 return do_request("/subscriptions/#{subscription_id}", conn, opts) end |
.fetch_active(master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/eme/subscription.rb', line 14 def self.fetch_active(master_account_id, conn = connection, opts = {}, reload = false) opts = opts_work(opts, "active-m-account-sub-#{master_account_id}") opts[:reload] ||= reload opts[:ttl] ||= 10 return do_request("/subscriptions/find_active_for_account/#{master_account_id}", conn, opts ) end |
.fetch_active_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/eme/subscription.rb', line 21 def self.fetch_active_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) opts = opts_work(opts, "active-m-game-account-sub-#{game_account_id}") opts[:reload] ||= reload opts[:ttl] ||= 10 return do_request("/subscriptions/find_active_for_game_account/#{game_account_id}", conn, opts ) end |
.fetch_all(master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/eme/subscription.rb', line 28 def self.fetch_all(master_account_id, conn = connection, opts = {}, reload = false) opts = opts_work(opts, "all-m-account-sub-#{master_account_id}") opts[:reload] ||= reload opts[:ttl] ||= 10 return do_request("/subscriptions/find_for_account/#{master_account_id}", conn, opts) end |
.fetch_all_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
35 36 37 38 39 |
# File 'lib/eme/subscription.rb', line 35 def self.fetch_all_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) opts = opts_work(opts, "all-m-game-account-sub-#{game_account_id}") opts[:reload] ||= reload return do_request("/subscriptions/find_for_game_account/#{game_account_id}", conn, opts) end |
.fetch_price_overrides_by_game_account_id(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
185 186 187 188 189 |
# File 'lib/eme/subscription.rb', line 185 def self.fetch_price_overrides_by_game_account_id(game_account_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload return do_request("/subscription_price_overrides/find_for_game_account/#{game_account_id}", conn, opts) end |
.price_override_logs(game_account_id, master_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/eme/subscription.rb', line 173 def self.price_override_logs(game_account_id, master_account_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:count] ||= 100 opts[:reverse] ||= false opts[:orderby] ||= "id" url = "/subscription_price_override_logs?orderby=#{opts[:orderby]}&reverse=#{opts[:reverse]}&count=#{opts[:count]}" url += "&game_account_id=#{game_account_id}" if game_account_id url += "&master_account_id=#{master_account_id}" if master_account_id return do_request(url, conn, opts) end |
.remove_days(sub_id, days, notes = nil, additional_info = nil, conn = connection, opts = {}, reload = false) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/eme/subscription.rb', line 141 def self.remove_days(sub_id, days, notes = nil, additional_info = nil, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post opts[:body] = {:days => days, :notes => notes, :additional_info => additional_info}.to_json results = do_request("/subscriptions/#{sub_id}/remove_days", conn, opts) clear_cache_for_subscription(sub_id) return results end |
.revive(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/eme/subscription.rb', line 76 def self.revive(sub_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post results = do_request("/subscriptions/#{sub_id}/revive", conn, opts) clear_cache_for_subscription(sub_id) return results end |
.subscription_info_for_game_account(game_account_id, conn = connection, opts = {}, reload = false) ⇒ Object
103 104 105 106 107 |
# File 'lib/eme/subscription.rb', line 103 def self.subscription_info_for_game_account(game_account_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload do_request("/subscriptions/get_subscription_info_by_game_account/#{game_account_id}", conn, opts) end |
.update(sub_id, conn = connection, opts = {}, reload = false) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/eme/subscription.rb', line 94 def self.update(sub_id, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post results = do_request("/subscriptions/#{sub_id}", conn, opts) clear_cache_for_subscription(sub_id) return results end |
.update_renew_price_by_game_account(game_account_id, price, conn = connection, opts = {}, reload = false) ⇒ Object
214 215 216 217 218 219 220 |
# File 'lib/eme/subscription.rb', line 214 def self.update_renew_price_by_game_account(game_account_id, price, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post opts[:body] = {:price => price}.to_json return do_request("/subscriptions/update_renew_price_by_game_account/#{game_account_id}", conn, opts) end |
.upsert_price_override(master_account_id, game_account_id, game_id, override_price, conn = connection, opts = {}, reload = false) ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/eme/subscription.rb', line 203 def self.upsert_price_override(master_account_id, game_account_id, game_id, override_price, conn = connection, opts ={}, reload = false) opts = opts_work(opts) opts[:reload] ||= reload opts[:method] = :post opts[:body] = {:master_account_id => master_account_id, :game_account_id => game_account_id, :game_id => game_id, :override_price => override_price}.to_json return do_request("/subscription_price_overrides/upsert", conn, opts) end |