xoxzo-cloudruby 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62d70753656e4100817c7d786f10512777377ede
4
- data.tar.gz: 2a3ca357a49b2d2567d6f767fa9d26c0617765ab
3
+ metadata.gz: 20b8dbe6b4b4c792c3eb918b2283e60401b275f8
4
+ data.tar.gz: 08fdea29480d7914e54148bb89ddf75e70ca966c
5
5
  SHA512:
6
- metadata.gz: b6b2a2c892402acc8b4c8d805d884fb096bca341ff82fce99e22b7e85afeff82ea1e72c6939b717e38d3d38b9053e843e80842b78edae706246cc8377a9442dd
7
- data.tar.gz: 8bc71724d76199c169b08f1499ff9f9a29f64867961a9243eece4392805c2e81179cbe7e296e2e4a5cfdd24c03b4f8732bb6285707e265b2894266773f9193db
6
+ metadata.gz: 20fc3388a54f6d939ed36e81063f8e12a3ca614165faf2328e701d6743e615a8e35248cacfa6f482e4c70db70e1e5283ae9b0233859b481568d9e099d57bfed1
7
+ data.tar.gz: a2b3a224464805ceabc3ed8ffb96527e696a9d88db70b568b00853f6ead4fadd0adcbb7c7eb44dc5103de331fae3a24d8a53fba45f0b934a9b6da5725f92ad9c
data/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ all:
2
+ gem build xoxzo-cloudruby.gemspec
data/README.md CHANGED
@@ -8,7 +8,7 @@ TODO: Delete this and the text above, and describe your gem
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- ```ruby
11
+ ```
12
12
  gem 'xoxzo-cloudruby'
13
13
  ```
14
14
 
@@ -22,7 +22,69 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Sample Code 1
26
+
27
+ Send SMS
28
+
29
+ require 'pp'
30
+ require 'xoxzo/cloudruby'
31
+ include Xoxzo::Cloudruby
32
+
33
+ sid = ENV['XOXZO_API_SID']
34
+ token = ENV['XOXZO_API_AUTH_TOKEN']
35
+ xc = XoxzoClient.new(sid,token)
36
+ res = xc.send_sms(message: "Hello! This is Xoxzo!", recipient: "+818012345678", sender: "8108012345678")
37
+ if res.errors != nil
38
+ pp res
39
+ exit -1
40
+ end
41
+
42
+ Sample Code 2
43
+
44
+ Simple Playback
45
+
46
+ sid = ENV['XOXZO_API_SID']
47
+ token = ENV['XOXZO_API_AUTH_TOKEN']
48
+ xc = XoxzoClient.new(sid,token)
49
+ res = xc.call_simple_playback(caller:"810812345678",recipient: "+818012345678",recording_url: "http://example.com/example.mp3")
50
+ if res.errors != nil
51
+ pp res
52
+ exit -1
53
+ end
54
+
55
+ callid = res.messages[0]['callid']
56
+ pp xc.get_simple_playback_status(callid: callid)
57
+
58
+ msgid = res.messages[0]['msgid']
59
+ res = xc.get_sms_delivery_status(msgid: msgid)
60
+ pp res
61
+
62
+ Sample Code 3
63
+
64
+ Get list of available DINs.
65
+
66
+ sid = ENV['XOXZO_API_SID']
67
+ token = ENV['XOXZO_API_AUTH_TOKEN']
68
+ xc = XoxzoClient.new(sid,token)
69
+ res = xc.get_din_list()
70
+ din_uid = res.message[0]['din_uid'] # get the din unique ID for the frist one for expample
71
+
72
+ Subscribe a DIN.
73
+
74
+ res = xc.subscribe_din(din_uid: din_uid)
75
+
76
+ Set the action url.
77
+
78
+ dummy_action_url = 'http://example.com/dummy_action'
79
+ res = xc.set_action_url(din_uid: din_uid, action_url: dummy_action_url)
80
+
81
+ Get the list of subscriptions.
82
+
83
+ res = xc.get_subscription_list()
84
+
85
+ Unsubscribe the DIN.
86
+
87
+ res = xc.unsubscribe_din(din_uid: din_uid)
26
88
 
27
89
  ## Development
28
90
 
@@ -32,5 +94,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
94
 
33
95
  ## Contributing
34
96
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xoxzo-cloudruby.
36
-
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xoxzo/xoxzo-cloudruby.
@@ -6,23 +6,38 @@ require 'json'
6
6
  module Xoxzo
7
7
  module Cloudruby
8
8
 
9
+ # Return object class for Xoxzo Cloud API
9
10
  class XoxzoRespose
10
11
  def initialize(errors: nil, message: Hash.new, messages: [])
12
+ # error status, nil if no errors
11
13
  @errors = errors
14
+ # return informaint in hash
12
15
  @message = message
16
+ # retrun information in array
13
17
  @messages = messages
14
18
  end
15
19
  attr_accessor :errors,:message,:messages
16
20
  end
17
21
 
22
+ # API obejet class Xoxzo service
18
23
  class XoxzoClient
24
+ # initialize xoxzo api client
25
+ # sid :: your api sid of Xoxzo account
26
+ # token :: your api token of Xoxzo account
27
+ # retrun :: XoxzoRespose
19
28
  def initialize(sid,token)
20
29
  @auth = {:username => sid, :password => token}
21
30
  api_host = "https://api.xoxzo.com"
22
31
  @xoxzo_api_sms_url = api_host + "/sms/messages/"
23
32
  @xoxzo_api_voice_simple_url = api_host + "/voice/simple/playback/"
33
+ @xoxzo_api_dins_url = api_host + "/voice/dins/"
24
34
  end
25
35
 
36
+ # send sms method
37
+ # messages :: sms text message
38
+ # recipient :: sms recipient phone numner eg. "+818012345678", remove first 0 in front of area number
39
+ # sender :: sem sender phone number. This value may not be displayed as is for some operators.
40
+ # retrun :: XoxzoRespose
26
41
  def send_sms(message:, recipient:, sender:)
27
42
  body = {"message" => message , "recipient" => recipient , "sender" => sender}
28
43
  res = HTTParty.post(@xoxzo_api_sms_url, :basic_auth => @auth,
@@ -36,6 +51,9 @@ module Xoxzo
36
51
  return xr
37
52
  end
38
53
 
54
+ # get sms delivery status method
55
+ # msgid :: message id of in the return value of the send_sms method.
56
+ # retrun :: XoxzoRespose
39
57
  def get_sms_delivery_status(msgid:)
40
58
  url = @xoxzo_api_sms_url + msgid
41
59
  res = HTTParty.get(url, :basic_auth => @auth)
@@ -47,6 +65,9 @@ module Xoxzo
47
65
  return xr
48
66
  end
49
67
 
68
+ # get setn sms list method
69
+ # send_data :: query string. eg. "=2016-05-18"
70
+ # retrun :: XoxzoRespose
50
71
  def get_sent_sms_list(sent_date: nil)
51
72
  if sent_date == nil
52
73
  url = @xoxzo_api_sms_url
@@ -62,6 +83,11 @@ module Xoxzo
62
83
  return xr
63
84
  end
64
85
 
86
+ # call simple palyback method
87
+ # caller :: caller phone number displayed on the recipient hand set
88
+ # recipient :: sms recipient phone numner eg. "+818012345678", remove first 0 in front of area number
89
+ # recording_url :: URL of the mp3 file to playback. eg. "http://example.com/example.mp3"
90
+ # retrun :: XoxzoRespose
65
91
  def call_simple_playback(caller:, recipient:, recording_url:)
66
92
  body = {"caller" => caller , "recipient" => recipient , "recording_url" => recording_url}
67
93
  res = HTTParty.post(@xoxzo_api_voice_simple_url, :basic_auth => @auth,
@@ -75,6 +101,9 @@ module Xoxzo
75
101
  return xr
76
102
  end
77
103
 
104
+ # get simple plaback status method
105
+ # callid :: call id in the return value of the call_simple_playback method
106
+ # retrun :: XoxzoRespose
78
107
  def get_simple_playback_status(callid:)
79
108
  url = @xoxzo_api_voice_simple_url + callid
80
109
  res = HTTParty.get(url, :basic_auth => @auth)
@@ -86,6 +115,72 @@ module Xoxzo
86
115
  return xr
87
116
  end
88
117
 
118
+ def get_din_list(search_string: nil)
119
+ if search_string == nil
120
+ url = @xoxzo_api_dins_url
121
+ else
122
+ url = @xoxzo_api_dins_url + '?' + search_string
123
+ end
124
+ res = HTTParty.get(url, :basic_auth => @auth)
125
+ if res.code == 200
126
+ xr = XoxzoRespose.new(message: json_safe_parse(res.body))
127
+ else
128
+ xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body))
129
+ end
130
+ return xr
131
+ end
132
+
133
+ def subscribe_din(din_uid:)
134
+ url = @xoxzo_api_dins_url + 'subscriptions/'
135
+ body = {"din_uid" => din_uid }
136
+ res = HTTParty.post(url, :basic_auth => @auth,
137
+ :body => body.to_json,
138
+ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
139
+ if res.code == 201
140
+ xr = XoxzoRespose.new(messages: json_safe_parse(res.body))
141
+ else
142
+ xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body))
143
+ end
144
+ return xr
145
+ end
146
+
147
+ def unsubscribe_din(din_uid:)
148
+ url = @xoxzo_api_dins_url + 'subscriptions/' + din_uid + '/'
149
+ res = HTTParty.delete(url, :basic_auth => @auth)
150
+ if res.code == 200
151
+ xr = XoxzoRespose.new(messages: json_safe_parse(res.body))
152
+ else
153
+ xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body))
154
+ end
155
+ return xr
156
+ end
157
+
158
+ def get_subscription_list()
159
+ url = @xoxzo_api_dins_url + 'subscriptions/'
160
+ res = HTTParty.get(url, :basic_auth => @auth)
161
+ if res.code == 200
162
+ xr = XoxzoRespose.new(messages: json_safe_parse(res.body))
163
+ else
164
+ xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body))
165
+ end
166
+ return xr
167
+ end
168
+
169
+ def set_action_url(din_uid:, action_url:)
170
+ url = @xoxzo_api_dins_url + 'subscriptions/' + din_uid + '/'
171
+ body = {'action_url': action_url}
172
+ res = HTTParty.post(url, :basic_auth => @auth,
173
+ :body => body.to_json,
174
+ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
175
+ if res.code == 200
176
+ xr = XoxzoRespose.new(messages: json_safe_parse(res.body))
177
+ else
178
+ xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body))
179
+ end
180
+ return xr
181
+ end
182
+
183
+ private
89
184
  def json_safe_parse(s)
90
185
  return JSON.parse(s)
91
186
  rescue JSON::ParserError => e
@@ -1,5 +1,5 @@
1
1
  module Xoxzo
2
2
  module Cloudruby
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/xoxzo-usage.rb CHANGED
@@ -5,7 +5,7 @@ require 'pp'
5
5
  sid = ENV['XOXZO_API_SID']
6
6
  token = ENV['XOXZO_API_AUTH_TOKEN']
7
7
  xc = XoxzoClient.new(sid,token)
8
- res = xc.send_sms(message: "Hello! This is Xoxzo!", recipient: "+818054695209", sender: "8108012345678")
8
+ res = xc.send_sms(message: "Hello! This is Xoxzo!", recipient: "+818012345678", sender: "8108012345678")
9
9
  if res.errors != nil
10
10
  pp res
11
11
  return
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xoxzo-cloudruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Nonaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-24 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -79,6 +79,7 @@ files:
79
79
  - ".travis.yml"
80
80
  - Gemfile
81
81
  - LICENSE
82
+ - Makefile
82
83
  - README.md
83
84
  - Rakefile
84
85
  - bin/console