Class: Textmagic::REST::Users

Inherits:
ListResource show all
Defined in:
lib/textmagic-ruby/rest/users.rb

Instance Method Summary collapse

Methods inherited from ListResource

#inspect

Methods included from Utils

#key_map, #resource, #to_camel_case, #to_underscore_case

Constructor Details

#initialize(path, client) ⇒ Users

Returns a new instance of Users.



4
5
6
# File 'lib/textmagic-ruby/rest/users.rb', line 4

def initialize(path, client)
  super path[0..-2], client
end

Instance Method Details

#create(params = {}) ⇒ Object

Creating is not supporred.



114
115
116
# File 'lib/textmagic-ruby/rest/users.rb', line 114

def create(params={})
  raise '`create` method is not supported for this resource.'
end

#delete(uid) ⇒ Object

Deleting is not supported.



107
108
109
# File 'lib/textmagic-ruby/rest/users.rb', line 107

def delete(uid)
  raise '`delete` method is not supported for this resource.'
end

#getObject



8
9
10
11
# File 'lib/textmagic-ruby/rest/users.rb', line 8

def get
  response = @client.get "#{@path}", {}
  @instance_class.new "#{@path}", @client, response
end

#list(params = {}) ⇒ Object

Listing is not supported.



79
80
81
# File 'lib/textmagic-ruby/rest/users.rb', line 79

def list(params={})
  raise '`list` method is not supported for this resource.'
end

#messaging_stat(params = {}) ⇒ Object

Return messaging statistics. Returns an array of hashes each contains messaging stats by given period.

The following params keys are supported:

by

Group results by specified period: ‘off`, `day`, `month` or `year`. Default is `off`.

start

Start date in unix timestamp format. Default is 7 days ago.

end

End date in unix timestamp format. Default is now.

Example:

@msg_stat = client.users.messaging_stat


47
48
49
50
# File 'lib/textmagic-ruby/rest/users.rb', line 47

def messaging_stat(params={})
  path = '/stats/messaging'
  response = @client.get path, params
end

#sources(params = {}) ⇒ Object

Get all available sender settings which could be used in “from” parameter of POST messages method. Returns Source object, contains arrays of allowed sender ids, shared and dedicated numbers.

The following params keys are supported:

country

Return sender settings available in specified country only. Optional.

Example:

@allowed = client.users.sources


25
26
27
28
29
# File 'lib/textmagic-ruby/rest/users.rb', line 25

def sources(params={})
  path = '/sources'
  response = @client.get path, params
  Source.new path, @client, response
end

#spending_stat(params = {}) ⇒ Object

Return account spending statistics. Returns a PaginateResource object contains array of SpendingStat objects.

The following params keys are supported:

page

Fetch specified results page. Defaults 1

limit

How many results on page. Defaults 10

start

Start date in unix timestamp format. Default is 7 days ago.

end

End date in unix timestamp format. Default is now.

Example:

@spend_stat = client.users.spending_stat


70
71
72
73
74
# File 'lib/textmagic-ruby/rest/users.rb', line 70

def spending_stat(params={})
  path = '/stats/spending'
  response = @client.get path, params
  PaginateResource.new path, @client, response, SpendingStat
end

#update(params = {}) ⇒ Object

Get current user info. Returns true if success.

The following params keys are supported:

first_name

User first name. Required.

last_name

User last name. Required.

company

User company. Required.

Example:

r = client.users.update {:first_name => 'Joye', :last_name => 'Tribbiani', :company => 'TextMagic'}


99
100
101
102
# File 'lib/textmagic-ruby/rest/users.rb', line 99

def update(params={})
  response = @client.put "#{@path}", params
  @instance_class.new "#{@path}", @client, response
end