CynSMS 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bfd24ed84d8207abd9c084a8f1a8f100b0dc3a86653761e412d8f150ecd5ff53
4
+ data.tar.gz: f7bc2f91f585a1336d09a9ea5914be0663ac91349f891b6354efaeadb81039e0
5
+ SHA512:
6
+ metadata.gz: cdc006259b63fd94fb6d7200fde2c7554964e63d3963f102b20cdc82c85148508b346b84c047f81a3adad401bdbb4c732f5a90b40eac762c31ae828bf3fd268a
7
+ data.tar.gz: 6d48dadb3a72660bcd0300c827c5e93d0896d07d4f05ec36ba6f7d5c5f18b4cb7df81659fd0a10854823925a3367b40d27869d8d78928400a68e227a6fbaa8af
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ License:
2
+ ========
3
+ The MIT License (MIT)
4
+ http://opensource.org/licenses/MIT
5
+
6
+ Copyright (c) 2014 - 2016 APIMATIC Limited
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+ Trade Mark:
27
+ ==========
28
+ APIMATIC is a trade mark for APIMATIC Limited
@@ -0,0 +1,176 @@
1
+ # Getting started
2
+
3
+ This Api is meant for 3rd party integrations
4
+
5
+ ## How to Build
6
+
7
+ This client library is a Ruby gem which can be compiled and used in your Ruby and Ruby on Rails project. This library requires a few gems from the RubyGems repository.
8
+
9
+ 1. Open the command line interface or the terminal and navigate to the folder containing the source code.
10
+ 2. Run ``` gem build cyn_sms.gemspec ``` to build the gem.
11
+ 3. Once built, the gem can be installed on the current work environment using ``` gem install cyn_sms-1.0.gem ```
12
+
13
+ ![Building Gem](https://apidocs.io/illustration/ruby?step=buildSDK&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSMS%20API-Ruby&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
14
+
15
+ ## How to Use
16
+
17
+ The following section explains how to use the CynSms Ruby Gem in a new Rails project using RubyMine™. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
18
+
19
+ ### 1. Starting a new project
20
+
21
+ Close any existing projects in RubyMine™ by selecting ``` File -> Close Project ```. Next, click on ``` Create New Project ``` to create a new project from scratch.
22
+
23
+ ![Create a new project in RubyMine](https://apidocs.io/illustration/ruby?step=createNewProject0&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
24
+
25
+ Next, provide ``` TestApp ``` as the project name, choose ``` Rails Application ``` as the project type, and click ``` OK ```.
26
+
27
+ ![Create a new Rails Application in RubyMine - step 1](https://apidocs.io/illustration/ruby?step=createNewProject1&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
28
+
29
+ In the next dialog make sure that correct *Ruby SDK* is being used (minimum 2.0.0) and click ``` OK ```.
30
+
31
+ ![Create a new Rails Application in RubyMine - step 2](https://apidocs.io/illustration/ruby?step=createNewProject2&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
32
+
33
+ This will create a new Rails Application project with an existing set of files and folder.
34
+
35
+ ### 2. Add reference of the gem
36
+
37
+ In order to use the CynSms gem in the new project we must add a gem reference. Locate the ```Gemfile``` in the *Project Explorer* window under the ``` TestApp ``` project node. The file contains references to all gems being used in the project. Here, add the reference to the library gem by adding the following line: ``` gem 'cyn_sms', '~> 1.0' ```
38
+
39
+ ![Add references of the Gemfile](https://apidocs.io/illustration/ruby?step=addReference&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
40
+
41
+ ### 3. Adding a new Rails Controller
42
+
43
+ Once the ``` TestApp ``` project is created, a folder named ``` controllers ``` will be visible in the *Project Explorer* under the following path: ``` TestApp > app > controllers ```. Right click on this folder and select ``` New -> Run Rails Generator... ```.
44
+
45
+ ![Run Rails Generator on Controllers Folder](https://apidocs.io/illustration/ruby?step=addCode0&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
46
+
47
+ Selecting the said option will popup a small window where the generator names are displayed. Here, select the ``` controller ``` template.
48
+
49
+ ![Create a new Controller](https://apidocs.io/illustration/ruby?step=addCode1&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
50
+
51
+ Next, a popup window will ask you for a Controller name and included Actions. For controller name provide ``` Hello ``` and include an action named ``` Index ``` and click ``` OK ```.
52
+
53
+ ![Add a new Controller](https://apidocs.io/illustration/ruby?step=addCode2&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
54
+
55
+ A new controller class anmed ``` HelloController ``` will be created in a file named ``` hello_controller.rb ``` containing a method named ``` Index ```. In this method, add code for initialization and a sample for its usage.
56
+
57
+ ![Initialize the library](https://apidocs.io/illustration/ruby?step=addCode3&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0)
58
+
59
+ ## How to Test
60
+
61
+ You can test the generated SDK and the server with automatically generated test
62
+ cases as follows:
63
+
64
+ 1. From terminal/cmd navigate to the root directory of the SDK.
65
+ 2. Invoke: `bundle exec rake`
66
+
67
+ ## Initialization
68
+
69
+ ###
70
+
71
+ API client can be initialized as following.
72
+
73
+ ```ruby
74
+
75
+ client = CynSms::CynSmsClient.new
76
+ ```
77
+
78
+ The added initlization code can be debugged by putting a breakpoint in the ``` Index ``` method and running the project in debug mode by selecting ``` Run -> Debug 'Development: TestApp' ```.
79
+
80
+ ![Debug the TestApp](https://apidocs.io/illustration/ruby?step=addCode4&workspaceFolder=CynSMS%20API-Ruby&workspaceName=CynSms&projectName=cyn_sms&gemName=cyn_sms&gemVer=1.0&initLine=client%2520%253D%2520CynSmsClient.new)
81
+
82
+
83
+
84
+ # Class Reference
85
+
86
+ ## <a name="list_of_controllers"></a>List of Controllers
87
+
88
+ * [APIController](#api_controller)
89
+
90
+ ## <a name="api_controller"></a>![Class: ](https://apidocs.io/img/class.png ".APIController") APIController
91
+
92
+ ### Get singleton instance
93
+
94
+ The singleton instance of the ``` APIController ``` class can be accessed from the API Client.
95
+
96
+ ```ruby
97
+ client_controller = client.client
98
+ ```
99
+
100
+ ### <a name="create_send_sms"></a>![Method: ](https://apidocs.io/img/method.png ".APIController.create_send_sms") create_send_sms
101
+
102
+ > TODO: Add a method description
103
+
104
+
105
+ ```ruby
106
+ def create_send_sms(api_key,
107
+ to,
108
+ sms,
109
+ from); end
110
+ ```
111
+
112
+ #### Parameters
113
+
114
+ | Parameter | Tags | Description |
115
+ |-----------|------|-------------|
116
+ | api_key | ``` Required ``` ``` DefaultValue ``` | set your API_KEY from http://sms.cynojine.com/sms-api/info (user panel) |
117
+ | to | ``` Required ``` ``` DefaultValue ``` | the number we are sending to - Any phone number |
118
+ | sms | ``` Required ``` | SMS Body |
119
+ | from | ``` Required ``` | Change the from number below. It can be a valid phone number or a String |
120
+
121
+
122
+ #### Example Usage
123
+
124
+ ```ruby
125
+ api_key = 'xxxxxxxxxxxxx'
126
+ to = '260986'
127
+ sms = 'sms'
128
+ from = 'from'
129
+
130
+ result = client_controller.create_send_sms(api_key, to, sms, from)
131
+
132
+ ```
133
+
134
+
135
+ ### <a name="get_balance_check"></a>![Method: ](https://apidocs.io/img/method.png ".APIController.get_balance_check") get_balance_check
136
+
137
+ > Checking SMS Balance
138
+
139
+
140
+ ```ruby
141
+ def get_balance_check(options = {},
142
+ _query_parameters = nil); end
143
+ ```
144
+
145
+ #### Parameters
146
+
147
+ | Parameter | Tags | Description |
148
+ |-----------|------|-------------|
149
+ | api_key | ``` Required ``` | Get your account balance |
150
+ | response | ``` Required ``` ``` DefaultValue ``` | Json Responce |
151
+ | _query_parameters | ``` Optional ``` | Additional optional query parameters are supported by this method |
152
+
153
+
154
+ #### Example Usage
155
+
156
+ ```ruby
157
+ collect = Hash.new
158
+
159
+ api_key = 'api_key'
160
+ collect['api_key'] = api_key
161
+
162
+ response = 'json'
163
+ collect['response'] = response
164
+
165
+ # key-value map for optional query parameters
166
+ queryParams = { 'key' => 'value' }
167
+
168
+ client_controller.get_balance_check(collect, queryParams, )
169
+
170
+ ```
171
+
172
+
173
+ [Back to List of Controllers](#list_of_controllers)
174
+
175
+
176
+
@@ -0,0 +1,34 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'date'
7
+ require 'json'
8
+ require 'faraday'
9
+ require 'certifi'
10
+ require 'logging'
11
+
12
+ require_relative 'cyn_sms/api_helper.rb'
13
+ require_relative 'cyn_sms/cyn_sms_client.rb'
14
+
15
+ # Http
16
+ require_relative 'cyn_sms/http/http_call_back.rb'
17
+ require_relative 'cyn_sms/http/http_client.rb'
18
+ require_relative 'cyn_sms/http/http_method_enum.rb'
19
+ require_relative 'cyn_sms/http/http_request.rb'
20
+ require_relative 'cyn_sms/http/http_response.rb'
21
+ require_relative 'cyn_sms/http/http_context.rb'
22
+ require_relative 'cyn_sms/http/faraday_client.rb'
23
+
24
+ # Models
25
+ require_relative 'cyn_sms/models/base_model.rb'
26
+
27
+ # Exceptions
28
+ require_relative 'cyn_sms/exceptions/api_exception.rb'
29
+
30
+ require_relative 'cyn_sms/configuration.rb'
31
+
32
+ # Controllers
33
+ require_relative 'cyn_sms/controllers/base_controller.rb'
34
+ require_relative 'cyn_sms/controllers/api_controller.rb'
@@ -0,0 +1,275 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # API utility class
8
+ class APIHelper
9
+ # Serializes an array parameter (creates key value pairs).
10
+ # @param [String] The name of the parameter.
11
+ # @param [Array] The value of the parameter.
12
+ # @param [String] The format of the serialization.
13
+ def self.serialize_array(key, array, formatting: 'indexed')
14
+ tuples = []
15
+
16
+ if formatting == 'unindexed'
17
+ tuples += array.map { |element| ["#{key}[]", element] }
18
+ elsif formatting == 'indexed'
19
+ tuples += array.map.with_index do |element, index|
20
+ ["#{key}[#{index}]", element]
21
+ end
22
+ elsif formatting == 'plain'
23
+ tuples += array.map { |element| [key, element] }
24
+ else
25
+ raise ArgumentError, 'Invalid format provided.'
26
+ end
27
+ tuples
28
+ end
29
+
30
+ # Replaces template parameters in the given url.
31
+ # @param [String] The query string builder to replace the template
32
+ # parameters.
33
+ # @param [Hash] The parameters to replace in the url.
34
+ def self.append_url_with_template_parameters(query_builder, parameters)
35
+ # perform parameter validation
36
+ unless query_builder.instance_of? String
37
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is
38
+ invalid.'
39
+ end
40
+
41
+ # Return if there are no parameters to replace.
42
+ return query_builder if parameters.nil?
43
+
44
+ # Iterate and append parameters.
45
+ parameters.each do |key, value|
46
+ replace_value = ''
47
+
48
+ if value.nil?
49
+ replace_value = ''
50
+ elsif value.instance_of? Array
51
+ value.map! { |element| CGI.escape(element.to_s) }
52
+ replace_value = value.join('/')
53
+ else
54
+ replace_value = CGI.escape(value.to_s)
55
+ end
56
+
57
+ # Find the template parameter and replace it with its value.
58
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
59
+ end
60
+ query_builder
61
+ end
62
+
63
+ # Appends the given set of parameters to the given query string.
64
+ # @param [String] The query string builder to add the query parameters to.
65
+ # @param [Hash] The parameters to append.
66
+ # @param [String] The format of array parameter serialization.
67
+ def self.append_url_with_query_parameters(query_builder, parameters,
68
+ array_serialization: 'indexed')
69
+ # Perform parameter validation.
70
+ unless query_builder.instance_of? String
71
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
72
+ is invalid.'
73
+ end
74
+
75
+ # Return if there are no parameters to replace.
76
+ return query_builder if parameters.nil?
77
+
78
+ parameters.each do |key, value|
79
+ seperator = query_builder.include?('?') ? '&' : '?'
80
+ unless value.nil?
81
+ if value.instance_of? Array
82
+ value.compact!
83
+ query_builder += if array_serialization == 'csv'
84
+ "#{seperator}#{key}=#{value.map do |element|
85
+ CGI.escape(element.to_s)
86
+ end.join(',')}"
87
+ elsif array_serialization == 'psv'
88
+ "#{seperator}#{key}=#{value.map do |element|
89
+ CGI.escape(element.to_s)
90
+ end.join('|')}"
91
+ elsif array_serialization == 'tsv'
92
+ "#{seperator}#{key}=#{value.map do |element|
93
+ CGI.escape(element.to_s)
94
+ end.join("\t")}"
95
+ else
96
+ "#{seperator}#{APIHelper.serialize_array(
97
+ key, value, formatting: array_serialization
98
+ ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
99
+ .join('&')}"
100
+ end
101
+ else
102
+ query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
103
+ end
104
+ end
105
+ end
106
+ query_builder
107
+ end
108
+
109
+ # Validates and processes the given Url.
110
+ # @param [String] The given Url to process.
111
+ # @return [String] Pre-processed Url as string.
112
+ def self.clean_url(url)
113
+ # Perform parameter validation.
114
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
115
+
116
+ # Ensure that the urls are absolute.
117
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
118
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
119
+
120
+ # Get the http protocol match.
121
+ protocol = matches[1]
122
+
123
+ # Check if parameters exist.
124
+ index = url.index('?')
125
+
126
+ # Remove redundant forward slashes.
127
+ query = url[protocol.length...(!index.nil? ? index : url.length)]
128
+ query.gsub!(%r{\/\/+}, '/')
129
+
130
+ # Get the parameters.
131
+ parameters = !index.nil? ? url[url.index('?')...url.length] : ''
132
+
133
+ # Return processed url.
134
+ protocol + query + parameters
135
+ end
136
+
137
+ # Parses JSON string.
138
+ # @param [String] A JSON string.
139
+ def self.json_deserialize(json)
140
+ return JSON.parse(json)
141
+ rescue StandardError
142
+ raise TypeError, 'Server responded with invalid JSON.'
143
+ end
144
+
145
+ # Removes elements with empty values from a hash.
146
+ # @param [Hash] The hash to clean.
147
+ def self.clean_hash(hash)
148
+ hash.delete_if { |_key, value| value.to_s.strip.empty? }
149
+ end
150
+
151
+ # Form encodes a hash of parameters.
152
+ # @param [Hash] The hash of parameters to encode.
153
+ # @return [Hash] A hash with the same parameters form encoded.
154
+ def self.form_encode_parameters(form_parameters)
155
+ encoded = {}
156
+ form_parameters.each do |key, value|
157
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
158
+ Configuration.array_serialization))
159
+ end
160
+ encoded
161
+ end
162
+
163
+ def self.custom_merge(a, b)
164
+ x = {}
165
+ a.each do |key, value_a|
166
+ b.each do |k, value_b|
167
+ next unless key == k
168
+ x[k] = []
169
+ if value_a.instance_of? Array
170
+ value_a.each do |v|
171
+ x[k].push(v)
172
+ end
173
+ else
174
+ x[k].push(value_a)
175
+ end
176
+ if value_b.instance_of? Array
177
+ value_b.each do |v|
178
+ x[k].push(v)
179
+ end
180
+ else
181
+ x[k].push(value_b)
182
+ end
183
+ a.delete(k)
184
+ b.delete(k)
185
+ end
186
+ end
187
+ x.merge!(a)
188
+ x.merge!(b)
189
+ x
190
+ end
191
+
192
+ # Form encodes an object.
193
+ # @param [Dynamic] An object to form encode.
194
+ # @param [String] The name of the object.
195
+ # @return [Hash] A form encoded representation of the object in the form
196
+ # of a hash.
197
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
198
+ retval = {}
199
+
200
+ serializable_types = [String, Numeric, TrueClass,
201
+ FalseClass, Date, DateTime]
202
+
203
+ # If this is a structure, resolve it's field names.
204
+ obj = obj.to_hash if obj.is_a? BaseModel
205
+
206
+ # Create a form encoded hash for this object.
207
+ if obj.nil?
208
+ nil
209
+ elsif obj.instance_of? Array
210
+ if formatting == 'indexed'
211
+ obj.each_with_index do |value, index|
212
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
213
+ index.to_s + ']'))
214
+ end
215
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
216
+ obj.each do |value|
217
+ abc = if formatting == 'unindexed'
218
+ APIHelper.form_encode(value, instance_name + '[]',
219
+ formatting: formatting)
220
+ else
221
+ APIHelper.form_encode(value, instance_name,
222
+ formatting: formatting)
223
+ end
224
+ retval = APIHelper.custom_merge(retval, abc)
225
+ # print retval
226
+ end
227
+ else
228
+ obj.each_with_index do |value, index|
229
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
230
+ index.to_s + ']', formatting: formatting))
231
+ end
232
+ end
233
+ elsif obj.instance_of? Hash
234
+ obj.each do |key, value|
235
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
236
+ key + ']', formatting: formatting))
237
+ end
238
+ else
239
+ retval[instance_name] = obj
240
+ end
241
+ retval
242
+ end
243
+
244
+ # Safely converts a string into an rfc3339 DateTime object
245
+ # @param [String] The datetime string
246
+ # @return [DateTime] A DateTime object of rfc3339 format
247
+ def self.rfc3339(date_time)
248
+ # missing timezone information
249
+ if date_time.end_with?('Z') || date_time.index('+')
250
+ DateTime.rfc3339(date_time)
251
+ else
252
+ DateTime.rfc3339(date_time + 'Z')
253
+ end
254
+ end
255
+ end
256
+ end
257
+
258
+ # Extend types to support to_bool.
259
+ module ToBoolean
260
+ def to_bool
261
+ return true if self == true || to_s.strip =~ /^(true|yes|y|1)$/i
262
+ false
263
+ end
264
+ end
265
+
266
+ # Extend NilClass type to support to_bool.
267
+ class NilClass; include ToBoolean; end
268
+ # Extend TrueClass type to support to_bool.
269
+ class TrueClass; include ToBoolean; end
270
+ # Extend FalseClass type to support to_bool.
271
+ class FalseClass; include ToBoolean; end
272
+ # Extend Numeric type to support to_bool.
273
+ class Numeric; include ToBoolean; end
274
+ # Extend String type to support to_bool.
275
+ class String; include ToBoolean; end
@@ -0,0 +1,20 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ # CohesityManagementSdk
7
+ module CynSms
8
+ # All configuration including auth info and base URI for the API access
9
+ # are configured in this class.
10
+ class Configuration
11
+ # The base Uri for API calls
12
+ @base_uri = 'http://sms.cynojine.com/sms'
13
+
14
+ # The attribute accessors for public properties.
15
+ class << self
16
+ attr_accessor :array_serialization
17
+ attr_accessor :base_uri
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,91 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # APIController
8
+ class APIController < BaseController
9
+ @instance = APIController.new
10
+
11
+ class << self
12
+ attr_accessor :instance
13
+ end
14
+
15
+ def instance
16
+ self.class.instance
17
+ end
18
+
19
+ # TODO: type endpoint description here
20
+ # @param [String] api_key Required parameter: set your API_KEY from
21
+ # http://sms.cynojine.com/sms-api/info (user panel)
22
+ # @param [String] to Required parameter: the number we are sending to - Any
23
+ # phone number
24
+ # @param [String] sms Required parameter: SMS Body
25
+ # @param [String] from Required parameter: Change the from number below. It
26
+ # can be a valid phone number or a String
27
+ # @return String response from the API call
28
+ def create_send_sms(api_key,
29
+ to,
30
+ sms,
31
+ from)
32
+ # Prepare query url.
33
+ _path_url = '/api?action=send-sms'
34
+ _query_builder = Configuration.base_uri.dup
35
+ _query_builder << _path_url
36
+ _query_builder = APIHelper.append_url_with_query_parameters(
37
+ _query_builder,
38
+ {
39
+ 'api key' => api_key,
40
+ 'to' => to,
41
+ 'sms' => sms,
42
+ 'from' => from
43
+ },
44
+ array_serialization: Configuration.array_serialization
45
+ )
46
+ _query_url = APIHelper.clean_url _query_builder
47
+ # Prepare and execute HttpRequest.
48
+ _request = @http_client.post(
49
+ _query_url
50
+ )
51
+ _context = execute_request(_request)
52
+ validate_response(_context)
53
+ # Return appropriate response type.
54
+ _context.response.raw_body
55
+ end
56
+
57
+ # Checking SMS Balance
58
+ # @param [String] api_key Required parameter: Get your account balance
59
+ # @param [String] response Required parameter: Json Responce
60
+ # @param [Hash] _query_parameters Additional optional query parameters are
61
+ # supported by this endpoint.
62
+ # @return void response from the API call
63
+ def get_balance_check(options = {},
64
+ _query_parameters = nil)
65
+ # Prepare query url.
66
+ _path_url = '/api?action=check-balance'
67
+ _query_builder = Configuration.base_uri.dup
68
+ _query_builder << _path_url
69
+ _query_builder = APIHelper.append_url_with_query_parameters(
70
+ _query_builder,
71
+ {
72
+ 'api_key' => options['api_key'],
73
+ 'response' => options['response']
74
+ },
75
+ array_serialization: Configuration.array_serialization
76
+ )
77
+ _query_builder = APIHelper.append_url_with_query_parameters(
78
+ _query_builder,
79
+ _query_parameters,
80
+ array_serialization: Configuration.array_serialization
81
+ )
82
+ _query_url = APIHelper.clean_url _query_builder
83
+ # Prepare and execute HttpRequest.
84
+ _request = @http_client.get(
85
+ _query_url
86
+ )
87
+ _context = execute_request(_request)
88
+ validate_response(_context)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,51 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # Base controller.
8
+ class BaseController
9
+ attr_accessor :http_client, :http_call_back
10
+
11
+ def initialize(http_client: nil, http_call_back: nil)
12
+ @http_client = http_client || FaradayClient.new
13
+ @http_call_back = http_call_back
14
+
15
+ @global_headers = {
16
+ 'user-agent' => 'APIMATIC 2.0'
17
+ }
18
+ end
19
+
20
+ def validate_parameters(args)
21
+ args.each do |_name, value|
22
+ if value.nil?
23
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
24
+ end
25
+ end
26
+ end
27
+
28
+ def execute_request(request, binary: false)
29
+ @http_call_back.on_before_request(request) if @http_call_back
30
+
31
+ APIHelper.clean_hash(request.headers)
32
+ request.headers = @global_headers.clone.merge(request.headers)
33
+
34
+ response = if binary
35
+ @http_client.execute_as_binary(request)
36
+ else
37
+ @http_client.execute_as_string(request)
38
+ end
39
+ context = HttpContext.new(request, response)
40
+
41
+ @http_call_back.on_after_response(context) if @http_call_back
42
+
43
+ context
44
+ end
45
+
46
+ def validate_response(context)
47
+ raise APIException.new 'HTTP Response Not OK', context unless
48
+ context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # cyn_sms client class.
8
+ class CynSmsClient
9
+ # Singleton access to client controller.
10
+ # @return [APIController] Returns the controller instance.
11
+ def client
12
+ APIController.instance
13
+ end
14
+
15
+ # Returns the configuration class for easy access.
16
+ # @return [Configuration] Returns the actual configuration class.
17
+ def config
18
+ Configuration
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # Class for exceptions when there is a network error, status code error, etc.
8
+ class APIException < StandardError
9
+ attr_reader :context, :response_code
10
+
11
+ # The constructor.
12
+ # @param [String] The reason for raising an exception.
13
+ # @param [HttpContext] The HttpContext of the API call.
14
+ def initialize(reason, context)
15
+ super(reason)
16
+ @context = context
17
+ @response_code = context.response.status_code
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,64 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'faraday/http_cache'
7
+ require 'faraday_middleware'
8
+
9
+ module CynSms
10
+ # An implementation of HttpClient.
11
+ class FaradayClient < HttpClient
12
+ # The constructor.
13
+ def initialize(timeout: nil, cache: false,
14
+ max_retries: nil, retry_interval: nil)
15
+ @connection = Faraday.new do |faraday|
16
+ faraday.use Faraday::HttpCache, serializer: Marshal if cache
17
+ faraday.use FaradayMiddleware::FollowRedirects
18
+ faraday.request :multipart
19
+ faraday.request :url_encoded
20
+ faraday.ssl[:ca_file] = Certifi.where
21
+ faraday.request :retry, max: max_retries, interval: if max_retries &&
22
+ retry_interval
23
+ retry_interval
24
+ end
25
+ faraday.adapter Faraday.default_adapter
26
+ faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
27
+ faraday.options[:open_timeout] = timeout if timeout
28
+ end
29
+ end
30
+
31
+ # Method overridden from HttpClient.
32
+ def execute_as_string(http_request)
33
+ response = @connection.send(
34
+ http_request.http_method.downcase,
35
+ http_request.query_url
36
+ ) do |request|
37
+ request.headers = http_request.headers
38
+ unless http_request.parameters.empty?
39
+ request.body = http_request.parameters
40
+ end
41
+ end
42
+ convert_response(response)
43
+ end
44
+
45
+ # Method overridden from HttpClient.
46
+ def execute_as_binary(http_request)
47
+ response = @connection.send(
48
+ http_request.http_method.downcase,
49
+ http_request.query_url
50
+ ) do |request|
51
+ request.headers = http_request.headers
52
+ unless http_request.parameters.empty?
53
+ request.body = http_request.parameters
54
+ end
55
+ end
56
+ convert_response(response)
57
+ end
58
+
59
+ # Method overridden from HttpClient.
60
+ def convert_response(response)
61
+ HttpResponse.new(response.status, response.headers, response.body)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # HttpCallBack allows defining callables for pre and post API calls.
8
+ class HttpCallBack
9
+ # A controller will call this method before making an HTTP Request.
10
+ # @param [HttpRequest] The HttpRequest object which the HttpClient
11
+ # will execute.
12
+ def on_before_request(_http_request)
13
+ raise NotImplementedError, 'This method needs
14
+ to be implemented in a child class.'
15
+ end
16
+
17
+ # A controller will call this method after making an HTTP Request.
18
+ # @param [HttpContext] The HttpContext of the API call.
19
+ def on_after_response(_http_context)
20
+ raise NotImplementedError, 'This method needs
21
+ to be implemented in a child class.'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,104 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # An interface for the methods that an HTTP Client must implement.
8
+ #
9
+ # This class should not be instantiated but should be used as a base class
10
+ # for HTTP Client classes.
11
+ class HttpClient
12
+ # Execute an HttpRequest when the response is expected to be a string.
13
+ # @param [HttpRequest] The HttpRequest to be executed.
14
+ def execute_as_string(_http_request)
15
+ raise NotImplementedError, 'This method needs
16
+ to be implemented in a child class.'
17
+ end
18
+
19
+ # Execute an HttpRequest when the response is expected to be binary.
20
+ # @param [HttpRequest] The HttpRequest to be executed.
21
+ def execute_as_binary(_http_request)
22
+ raise NotImplementedError, 'This method needs
23
+ to be implemented in a child class.'
24
+ end
25
+
26
+ # Converts the HTTP Response from the client to an HttpResponse object.
27
+ # @param [Dynamic] The response object received from the client.
28
+ def convert_response(_response)
29
+ raise NotImplementedError, 'This method needs
30
+ to be implemented in a child class.'
31
+ end
32
+
33
+ # Get a GET HttpRequest object.
34
+ # @param [String] The URL to send the request to.
35
+ # @param [Hash, Optional] The headers for the HTTP Request.
36
+ def get(query_url,
37
+ headers: {})
38
+ HttpRequest.new(HttpMethodEnum::GET,
39
+ query_url,
40
+ headers: headers)
41
+ end
42
+
43
+ # Get a HEAD HttpRequest object.
44
+ # @param [String] The URL to send the request to.
45
+ # @param [Hash, Optional] The headers for the HTTP Request.
46
+ def head(query_url,
47
+ headers: {})
48
+ HttpRequest.new(HttpMethodEnum::HEAD,
49
+ query_url,
50
+ headers: headers)
51
+ end
52
+
53
+ # Get a POST HttpRequest object.
54
+ # @param [String] The URL to send the request to.
55
+ # @param [Hash, Optional] The headers for the HTTP Request.
56
+ # @param [Hash, Optional] The parameters for the HTTP Request.
57
+ def post(query_url,
58
+ headers: {},
59
+ parameters: {})
60
+ HttpRequest.new(HttpMethodEnum::POST,
61
+ query_url,
62
+ headers: headers,
63
+ parameters: parameters)
64
+ end
65
+
66
+ # Get a PUT HttpRequest object.
67
+ # @param [String] The URL to send the request to.
68
+ # @param [Hash, Optional] The headers for the HTTP Request.
69
+ # @param [Hash, Optional] The parameters for the HTTP Request.
70
+ def put(query_url,
71
+ headers: {},
72
+ parameters: {})
73
+ HttpRequest.new(HttpMethodEnum::PUT,
74
+ query_url,
75
+ headers: headers,
76
+ parameters: parameters)
77
+ end
78
+
79
+ # Get a PATCH HttpRequest object.
80
+ # @param [String] The URL to send the request to.
81
+ # @param [Hash, Optional] The headers for the HTTP Request.
82
+ # @param [Hash, Optional] The parameters for the HTTP Request.
83
+ def patch(query_url,
84
+ headers: {},
85
+ parameters: {})
86
+ HttpRequest.new(HttpMethodEnum::PATCH,
87
+ query_url,
88
+ headers: headers,
89
+ parameters: parameters)
90
+ end
91
+
92
+ # Get a DELETE HttpRequest object.
93
+ # @param [String] The URL to send the request to.
94
+ # @param [Hash, Optional] The headers for the HTTP Request.
95
+ def delete(query_url,
96
+ headers: {},
97
+ parameters: {})
98
+ HttpRequest.new(HttpMethodEnum::DELETE,
99
+ query_url,
100
+ headers: headers,
101
+ parameters: parameters)
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,20 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # Represents an Http call in context.
8
+ class HttpContext
9
+ attr_accessor :request, :response
10
+
11
+ # The constructor.
12
+ # @param [HttpRequest] An HttpRequest object representing the HTTP request.
13
+ # @param [HttpResponse] An HttpResponse object representing the HTTP
14
+ # response.
15
+ def initialize(request, response)
16
+ @request = request
17
+ @response = response
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # HTTP Methods Enumeration.
8
+ class HttpMethodEnum
9
+ HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
10
+ PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
11
+ DELETE = 'DELETE'.freeze, HEAD = 'HEAD'.freeze].freeze
12
+ end
13
+ end
@@ -0,0 +1,50 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # Represents a single Http Request.
8
+ class HttpRequest
9
+ attr_accessor :http_method, :query_url, :headers,
10
+ :parameters, :username, :password
11
+
12
+ # The constructor.
13
+ # @param [HttpMethodEnum] The HTTP method.
14
+ # @param [String] The URL to send the request to.
15
+ # @param [Hash, Optional] The headers for the HTTP Request.
16
+ # @param [Hash, Optional] The parameters for the HTTP Request.
17
+ def initialize(http_method,
18
+ query_url,
19
+ headers: {},
20
+ parameters: {})
21
+ @http_method = http_method
22
+ @query_url = query_url
23
+ @headers = headers
24
+ @parameters = parameters
25
+ end
26
+
27
+ # Add a header to the HttpRequest.
28
+ # @param [String] The name of the header.
29
+ # @param [String] The value of the header.
30
+ def add_header(name, value)
31
+ @headers[name] = value
32
+ end
33
+
34
+ # Add a parameter to the HttpRequest.
35
+ # @param [String] The name of the parameter.
36
+ # @param [String] The value of the parameter.
37
+ def add_parameter(name, value)
38
+ @parameters[name] = value
39
+ end
40
+
41
+ # Add a query parameter to the HttpRequest.
42
+ # @param [String] The name of the query parameter.
43
+ # @param [String] The value of the query parameter.
44
+ def add_query_parameter(name, value)
45
+ @query_url = APIHelper.append_url_with_query_parameters(@query_url,
46
+ name => value)
47
+ @query_url = APIHelper.clean_url(@query_url)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,23 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # Http response received.
8
+ class HttpResponse
9
+ attr_accessor :status_code, :headers, :raw_body
10
+
11
+ # The constructor
12
+ # @param [Integer] The status code returned by the server.
13
+ # @param [Hash] The headers sent by the server in the response.
14
+ # @param [String] The raw body of the response.
15
+ def initialize(status_code,
16
+ headers,
17
+ raw_body)
18
+ @status_code = status_code
19
+ @headers = headers
20
+ @raw_body = raw_body
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ # cyn_sms
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module CynSms
7
+ # Base model.
8
+ class BaseModel
9
+ # Returns a Hash representation of the current object.
10
+ def to_hash
11
+ hash = {}
12
+ instance_variables.each do |name|
13
+ value = instance_variable_get(name)
14
+ name = name[1..-1]
15
+ key = self.class.names.key?(name) ? self.class.names[name] : name
16
+ if value.instance_of? Array
17
+ hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
18
+ elsif value.instance_of? Hash
19
+ hash[key] = {}
20
+ value.each do |k, v|
21
+ hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
22
+ end
23
+ else
24
+ hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
25
+ end
26
+ end
27
+ hash
28
+ end
29
+
30
+ # Returns a JSON representation of the curent object.
31
+ def to_json(options = {})
32
+ hash = to_hash
33
+ hash.to_json(options)
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: CynSMS
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - kazashim kuzasuwat
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logging
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.1.5
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.1'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.1.5
75
+ - !ruby/object:Gem::Dependency
76
+ name: certifi
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2016'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2016'
89
+ - !ruby/object:Gem::Dependency
90
+ name: faraday-http-cache
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.2'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.2.2
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.2'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 1.2.2
109
+ description: This Api is meant for 3rd party integrations
110
+ email: kazashim@cynojine.com
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files: []
114
+ files:
115
+ - LICENSE
116
+ - README.md
117
+ - lib/cyn_sms.rb
118
+ - lib/cyn_sms/api_helper.rb
119
+ - lib/cyn_sms/configuration.rb
120
+ - lib/cyn_sms/controllers/api_controller.rb
121
+ - lib/cyn_sms/controllers/base_controller.rb
122
+ - lib/cyn_sms/cyn_sms_client.rb
123
+ - lib/cyn_sms/exceptions/api_exception.rb
124
+ - lib/cyn_sms/http/faraday_client.rb
125
+ - lib/cyn_sms/http/http_call_back.rb
126
+ - lib/cyn_sms/http/http_client.rb
127
+ - lib/cyn_sms/http/http_context.rb
128
+ - lib/cyn_sms/http/http_method_enum.rb
129
+ - lib/cyn_sms/http/http_request.rb
130
+ - lib/cyn_sms/http/http_response.rb
131
+ - lib/cyn_sms/models/base_model.rb
132
+ homepage: https://cynojine.com
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '2.0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.7.6
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: cyn_sms
156
+ test_files: []