Class: Rest

Inherits:
Object
  • Object
show all
Defined in:
lib/rest.rb

Constant Summary collapse

@@path =
"https://rest.payamak-panel.com/api/SendSMS/%s"

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Rest

Returns a new instance of Rest.



6
7
8
9
# File 'lib/rest.rb', line 6

def initialize(username, password)
   @username = username
   @password = password
end

Instance Method Details

#get_base_priceObject



67
68
69
70
# File 'lib/rest.rb', line 67

def get_base_price
    url = sprintf @@path,"GetBasePrice"
    request(url,get_data)
end

#get_creditObject



62
63
64
65
# File 'lib/rest.rb', line 62

def get_credit
    url = sprintf @@path,"GetCredit"
    request(url,get_data)
end

#get_dataObject



11
12
13
14
15
16
# File 'lib/rest.rb', line 11

def get_data
    {
        :username => @username,
        :password => @password
    }
end

#get_messages(location, index, count, from = "") ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/rest.rb', line 51

def get_messages(location, index, count, from="")
    url = sprintf @@path,"GetMessages"
    data = {
        :location=>location,
        :index=> index,
        :count=> count,
        :from=> from
    }
    request(url,data.merge(get_data))
end

#get_numbersObject



72
73
74
75
# File 'lib/rest.rb', line 72

def get_numbers
    url = sprintf @@path,"GetUserNumbers"
    request(url,get_data)
end

#is_delivered(recId) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rest.rb', line 43

def is_delivered(recId)
    url = sprintf @@path,"GetDeliveries2"
    data = {
        :recId=>recId,
    }
    request(url,data.merge(get_data))
end

#request(url, params) ⇒ Object



18
19
20
# File 'lib/rest.rb', line 18

def request(url,params)
    HTTP.post(url, :form => params).parse
end

#send(to, from, text, isFlash = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rest.rb', line 22

def send(to,from,text,isFlash=false)
    url = sprintf @@path,"SendSMS"
    data = {
        :to=>to,
        :from=>from,
        :text=>text,
        :isFlash=>isFlash
    }
    request(url,data.merge(get_data))
end

#send_by_base_number(text, to, bodyId) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/rest.rb', line 33

def send_by_base_number(text, to, bodyId)
    url = sprintf @@path,"BaseServiceNumber"
    data = {
        :text=>text,
        :to=>to,
        :bodyId=>bodyId
    }
    request(url,data.merge(get_data))
end