Class: CTM::Base
Direct Known Subclasses
Account, AvailableNumber, Call, Message, Number, ReceivingNumber, Sale, Source, User, Webhook
Defined Under Namespace
Classes: Location
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, token = nil) ⇒ Base
constructor
A new instance of Base.
- #release! ⇒ Object
- #save(options = {}) ⇒ Object
Constructor Details
#initialize(data, token = nil) ⇒ Base
Returns a new instance of Base.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ctm/base.rb', line 20 def initialize(data, token=nil) @token = token || CTM::Auth.token @account_id = data['account_id'] @list_token_type = case self.class.to_s when 'CTM::Sale' then 'calls' else self.class.to_s.sub(/CTM::/,'').underscore.pluralize end if @account_id @list_type_path = "accounts/#{@account_id}/#{@list_token_type}" else @list_type_path = @list_token_type end end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
17 18 19 |
# File 'lib/ctm/base.rb', line 17 def account_id @account_id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
17 18 19 |
# File 'lib/ctm/base.rb', line 17 def token @token end |
Class Method Details
.create(options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ctm/base.rb', line 48 def self.create() list_type_path = .delete(:list_type_path) list_token_type = .delete(:list_token_type) account_id = .delete(:account_id) token = .delete(:token) path_str = "/api/v1/#{list_type_path}.json" #puts "create: #{self}(#{path_str}) -> #{options.inspect}" res = self.post(path_str, :body => .merge(:auth_token => token)) #puts "result: #{res.parsed_response.inspect}" #puts "properties: #{list_type_path.inspect} -> #{list_token_type.inspect} -> #{account_id}" if res.parsed_response['status'] == 'error' raise CTM::Error::Create.new(res.parsed_response['reason']) else self.new(res.parsed_response[list_token_type.singularize], token) end end |
Instance Method Details
#release! ⇒ Object
42 43 44 45 46 |
# File 'lib/ctm/base.rb', line 42 def release! path_str = "/api/v1/#{@list_type_path}/#{@id}.json" res = self.class.delete(path_str, :body => {:auth_token => @token}) res.parsed_response end |
#save(options = {}) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ctm/base.rb', line 35 def save(={}) #puts "save: #{options.inspect}" path_str = "/api/v1/#{@list_type_path}/#{@id}.json" #puts path_str self.class.put(path_str, :body => .merge(:auth_token => @token)) end |