Class: RestAsync

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ RestAsync



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

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

Instance Method Details

#get_base_priceObject



82
83
84
85
86
87
88
# File 'lib/restAsync.rb', line 82

def get_base_price
    url = sprintf @@path,"GetBasePrice"
    result = nil
    t = Thread.new{ result = request(url,get_data) }
    t.join
    result
end

#get_creditObject



74
75
76
77
78
79
80
# File 'lib/restAsync.rb', line 74

def get_credit
    url = sprintf @@path,"GetCredit"
    result = nil
    t = Thread.new{ result = request(url,get_data) }
    t.join
    result
end

#get_dataObject



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

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

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



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/restAsync.rb', line 60

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

#get_numbersObject



90
91
92
93
94
95
96
# File 'lib/restAsync.rb', line 90

def get_numbers
    url = sprintf @@path,"GetUserNumbers"
    result = nil
    t = Thread.new{ result = request(url,get_data) }
    t.join
    result
end

#is_delivered(recId) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/restAsync.rb', line 49

def is_delivered(recId)
    url = sprintf @@path,"GetDeliveries2"
    data = {
        :recId=>recId,
    }
    result = nil
    t = Thread.new{ result = request(url,data.merge(get_data)) }
    t.join
    result
end

#request(url, params) ⇒ Object



18
19
20
# File 'lib/restAsync.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
32
33
34
# File 'lib/restAsync.rb', line 22

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

#send_by_base_number(text, to, bodyId) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/restAsync.rb', line 36

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