codec_fast_sms 0.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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +13 -0
- data/Gemfile +8 -0
- data/README.md +79 -0
- data/Rakefile +18 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/codec_fast_sms.gemspec +32 -0
- data/lib/codec_fast_sms.rb +13 -0
- data/lib/codec_fast_sms/client.rb +31 -0
- data/lib/codec_fast_sms/configuration.rb +50 -0
- data/lib/codec_fast_sms/core.rb +30 -0
- data/lib/codec_fast_sms/version.rb +5 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fee74c51b4b78963c7c059abc8c2e4cecc586ae57c50ee9473569faa888649c3
|
4
|
+
data.tar.gz: abd5a1e4a5e04ae432926b913bf3dbad235ab10c08b55ed581270d3880291e4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be1fb5ccd3a310fc1eab86863dc9e12c8c4614b5e7eb8d8f0c6b996fe094b08f38a33b23495b56f4ab60dadedd96c5d283369e6e219a036a44c75b438e76b435
|
7
|
+
data.tar.gz: fd0e213ac6bf2cae091e841cfa73d7e6fdbb599ab25e2367b569e0dcfe4d2192eb21811091e581f38a78a831466307e9558965de82e2c1915bcfa713ac1b6301
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
2
|
+
# configuration file. It makes it possible to enable/disable
|
3
|
+
# certain cops (checks) and to alter their behavior if they accept
|
4
|
+
# any parameters. The file can be placed either in your home
|
5
|
+
# directory or in some project directory.
|
6
|
+
#
|
7
|
+
# RuboCop will start looking for the configuration file in the directory
|
8
|
+
# where the inspected file is and continue its way up to the root directory.
|
9
|
+
#
|
10
|
+
# See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# CodecFastSms [](https://travis-ci.org/sertangulveren/codec_fast_sms)
|
2
|
+
|
3
|
+
This client allows you to send sms using Codec Fast SMS API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'codec_fast_sms'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install codec_fast_sms
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Client must be configured before use. Configuration fields are as:
|
24
|
+
|
25
|
+
| Field | Description |
|
26
|
+
| --------------- | ------------------------------------------------------------------------------------------------------- |
|
27
|
+
| api_host | Root url of the API. |
|
28
|
+
| username | Your API username. |
|
29
|
+
| password | Your API password. |
|
30
|
+
| sender | Sms sender title. |
|
31
|
+
|
32
|
+
### Configuration on Rails Application:
|
33
|
+
Create a file in the `config/initializers` directory and configure client in this file as below:
|
34
|
+
`# config/initializers/codec_fast_sms.rb`
|
35
|
+
```ruby
|
36
|
+
CodecFastSms.configure do |config|
|
37
|
+
config.api_host = 'https://fastsms.api.example.com'
|
38
|
+
config.username = 'mysuperapiuser'
|
39
|
+
config.password = 'mYsupeRsecreTqassworld'
|
40
|
+
config.sender = 'MYSUPERCOMPANY'
|
41
|
+
end
|
42
|
+
```
|
43
|
+
### Multiple Configuration
|
44
|
+
You can define multiple configurations separated by profile. To do this, you must pass the profile parameter to the `configure` definition.
|
45
|
+
If the profile name is not pass in the configuration, it defaults to use `:default`.
|
46
|
+
##### Example:
|
47
|
+
In this example, to send sms , profile name specified as `settings`.
|
48
|
+
`# config/initializers/codec_otp_settings.rb`
|
49
|
+
```ruby
|
50
|
+
CodecFastSms.configure(:otp_user) do |config|
|
51
|
+
config.api_host = 'https://fastsms.api.example.com'
|
52
|
+
config.username = 'mysuperapiotpuser'
|
53
|
+
config.password = 'mYsupeRsecreTqassworldforOtP'
|
54
|
+
config.sender = 'MYSUPERCOMPANY'
|
55
|
+
end
|
56
|
+
```
|
57
|
+
## Usage
|
58
|
+
Initialize a client object before starting process.
|
59
|
+
```ruby
|
60
|
+
client = CodecFastSms::Client.new
|
61
|
+
```
|
62
|
+
To send sms, call the method `deliver`.
|
63
|
+
```ruby
|
64
|
+
phone = '905991112233'
|
65
|
+
message = 'Dear Hayri Gülümser, your membership has been activated.'
|
66
|
+
client.deliver(phone, message)
|
67
|
+
puts client.response
|
68
|
+
```
|
69
|
+
|
70
|
+
We can pass the profile argument on client initialization to use different configuration.
|
71
|
+
```ruby
|
72
|
+
client = CodecFastSms::Client.new(profile: :dynamic_settings)
|
73
|
+
client.deliver(phone, message)
|
74
|
+
```
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sertangulveren/codec_fast_sms.
|
79
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << 'test'
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.test_files = FileList['test/**/*_test.rb']
|
11
|
+
t.warning = false
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :test
|
15
|
+
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
|
18
|
+
task default: %i[test rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'codec_fast_sms'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/codec_fast_sms/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'codec_fast_sms'
|
7
|
+
spec.version = CodecFastSms::VERSION
|
8
|
+
spec.authors = ['Sertan Gülveren']
|
9
|
+
spec.email = ['sertangulveren@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Codec FastSMS Library for Ruby.'
|
12
|
+
spec.description = 'It is a simple ruby client for Codec FastSMS API.'
|
13
|
+
spec.homepage = 'https://github.com/sertangulveren/codec_fast_sms'
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
spec.add_development_dependency('minitest', '~> 5.0')
|
26
|
+
spec.add_development_dependency('rake', '~> 12.0')
|
27
|
+
spec.add_development_dependency('rubocop', '~> 0.79.0')
|
28
|
+
spec.add_development_dependency('simplecov', '~> 0.17.1')
|
29
|
+
spec.add_development_dependency('webmock', '~> 3.8')
|
30
|
+
|
31
|
+
spec.add_dependency('faraday', '~> 0.11.0')
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'codec_fast_sms/version'
|
5
|
+
require 'codec_fast_sms/configuration'
|
6
|
+
require 'codec_fast_sms/core'
|
7
|
+
require 'codec_fast_sms/client'
|
8
|
+
module CodecFastSms
|
9
|
+
class Error < StandardError; end
|
10
|
+
class ProfileNotFound < Error; end
|
11
|
+
class InvalidExtension < Error; end
|
12
|
+
class NoProfilesWereFound < Error; end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodecFastSms
|
4
|
+
# Client
|
5
|
+
class Client < Core
|
6
|
+
# Api endpoint.
|
7
|
+
def request_uri
|
8
|
+
'/FastApi.asmx/SendSms'
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
{
|
13
|
+
userName: ::CodecFastSms.configuration(profile).username,
|
14
|
+
password: ::CodecFastSms.configuration(profile).password,
|
15
|
+
sender: ::CodecFastSms.configuration(profile).sender,
|
16
|
+
phone: to, messageContent: message, msgSpecialId: '', isOtn: 'True',
|
17
|
+
headerCode: '', responseType: '3', optionalParameters: ''
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def assign_recipient_information(to, message)
|
22
|
+
self.to = to
|
23
|
+
self.message = message
|
24
|
+
end
|
25
|
+
|
26
|
+
def deliver(to, message)
|
27
|
+
assign_recipient_information(to, message)
|
28
|
+
perform
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# main module
|
4
|
+
module CodecFastSms
|
5
|
+
class << self
|
6
|
+
attr_accessor :configurations
|
7
|
+
|
8
|
+
def configuration(profile = :default)
|
9
|
+
raise NoProfilesWereFound if configurations.nil? || configurations.empty?
|
10
|
+
|
11
|
+
configurations.select do |conf|
|
12
|
+
conf.profile == profile
|
13
|
+
end.first || raise(ProfileNotFound, "Undefined profile: #{profile}")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def reject_profile(profile)
|
19
|
+
configurations.reject! { |conf| conf.profile == profile }
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize_configuration
|
23
|
+
self.configurations = [] if configurations.nil?
|
24
|
+
Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def after_configuration_events(conf, profile)
|
28
|
+
conf.profile = profile # FORCE!
|
29
|
+
reject_profile(profile)
|
30
|
+
configurations << conf
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.configure(profile = :default)
|
35
|
+
conf = initialize_configuration
|
36
|
+
yield(conf)
|
37
|
+
after_configuration_events(conf, profile)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Configuration class
|
41
|
+
class Configuration
|
42
|
+
EXTENSION_TYPES = %w[yml json].freeze
|
43
|
+
|
44
|
+
attr_accessor :profile, :api_host, :username, :password, :sender
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
self.profile = :default
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodecFastSms
|
4
|
+
# Core
|
5
|
+
class Core
|
6
|
+
attr_accessor :connection, :profile, :response, :to, :message
|
7
|
+
def initialize(profile: :default)
|
8
|
+
self.profile = profile
|
9
|
+
# Firstly, create a connection object.
|
10
|
+
self.connection = Faraday.new(
|
11
|
+
url: ::CodecFastSms.configuration(profile).api_host
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Call the api and process the response.
|
16
|
+
def perform
|
17
|
+
resp = connection.get(request_uri) do |req|
|
18
|
+
req.params = params
|
19
|
+
end
|
20
|
+
self.response = resp.body
|
21
|
+
# If server returns 200, everything is OK.
|
22
|
+
true
|
23
|
+
rescue Faraday::Error => e
|
24
|
+
self.response = { message: e.message }
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def params; end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codec_fast_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sertan Gülveren
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.79.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.79.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.17.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.17.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.11.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.11.0
|
97
|
+
description: It is a simple ruby client for Codec FastSMS API.
|
98
|
+
email:
|
99
|
+
- sertangulveren@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- codec_fast_sms.gemspec
|
113
|
+
- lib/codec_fast_sms.rb
|
114
|
+
- lib/codec_fast_sms/client.rb
|
115
|
+
- lib/codec_fast_sms/configuration.rb
|
116
|
+
- lib/codec_fast_sms/core.rb
|
117
|
+
- lib/codec_fast_sms/version.rb
|
118
|
+
homepage: https://github.com/sertangulveren/codec_fast_sms
|
119
|
+
licenses: []
|
120
|
+
metadata:
|
121
|
+
homepage_uri: https://github.com/sertangulveren/codec_fast_sms
|
122
|
+
source_code_uri: https://github.com/sertangulveren/codec_fast_sms
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.1.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Codec FastSMS Library for Ruby.
|
142
|
+
test_files: []
|