smsfly 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc8375d7bad96dc25e573799eaeaab707c3b35da
4
- data.tar.gz: 3e637c794e5932ee5e5f461c6da1703270af72cc
3
+ metadata.gz: 783b927fbbb176c1f7d92bd9333fb25ec1be4fa9
4
+ data.tar.gz: 52e17a87e3f2274cc6adce98911831a41f9ff7e4
5
5
  SHA512:
6
- metadata.gz: 954662afc4ec4aab917411aaaafdece5fa29da9d8c141b4b2c232bcd2dbecb29161cc8db1dced9fd76d0096cf7432b79ee6548a2c4400ef8d9b17e41b02369bf
7
- data.tar.gz: e6daf593cad77e15ccac1b9661aea072ca28b95586cd13130efbe3a42443286286fef2590becc6373e6437be308f7ed716a2670d3e6458f842361bea2b4bbbd0
6
+ metadata.gz: 8326e61078077d614f37fb0a4483401493374d56c4affef1f4005183909d15f22b4ecb799602ab8746d6c24fdff3330dc2750bf7c67b65268c291042cada5d33
7
+ data.tar.gz: f461b00a9ce9f232c17f66e6ae4699b346084c63627221b904438ef8b5f33cdd5f9879d6c57ea45d2752bbba52ee5942a2cbd826c3d112ab3bd9bce8a54696c0
data/README.md CHANGED
@@ -10,7 +10,7 @@ TODO:
10
10
  Add this line to your application's Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'smsfly', '~> 0.4.1'
13
+ gem 'smsfly', '~> 0.4.3'
14
14
  ```
15
15
 
16
16
  And then execute:
@@ -39,7 +39,14 @@ Smsfly.configuration do |config|
39
39
  end
40
40
  ```
41
41
 
42
+ Test connection to API:
42
43
 
44
+ ```ruby
45
+ Smsfly.authentication?
46
+ #this return
47
+ true #- If authentication is successful
48
+ false #- If authentication failed
49
+ ```
43
50
 
44
51
 
45
52
  ## Usage
data/lib/smsfly.rb CHANGED
@@ -25,6 +25,48 @@ module Smsfly
25
25
  end
26
26
  end
27
27
 
28
+ def self.colorize(text, color = "default", bgColor = "default")
29
+ colors = {"default" => "38","black" => "30","red" => "31","green" => "32","brown" => "33", "blue" => "34", "purple" => "35",
30
+ "cyan" => "36", "gray" => "37", "dark gray" => "1;30", "light red" => "1;31", "light green" => "1;32", "yellow" => "1;33",
31
+ "light blue" => "1;34", "light purple" => "1;35", "light cyan" => "1;36", "white" => "1;37"}
32
+ bgColors = {"default" => "0", "black" => "40", "red" => "41", "green" => "42", "brown" => "43", "blue" => "44",
33
+ "purple" => "45", "cyan" => "46", "gray" => "47", "dark gray" => "100", "light red" => "101", "light green" => "102",
34
+ "yellow" => "103", "light blue" => "104", "light purple" => "105", "light cyan" => "106", "white" => "107"}
35
+ color_code = colors[color]
36
+ bgColor_code = bgColors[bgColor]
37
+ return "\033[#{bgColor_code};#{color_code}m#{text}\033[0m"
38
+ end
39
+
40
+
41
+
42
+ def self.authentication?
43
+ xml_string = <<XML
44
+ <?xml version="1.0" encoding="utf-8"?>
45
+ <request>
46
+ <operation>GETBALANCE</operation>
47
+ </request>
48
+ XML
49
+ full_url = "http://sms-fly.com/api/api.php"
50
+ uri = URI.parse(full_url)
51
+ headers = {'Content-Type' => "text/xml", 'Accept' => "text/xml" }
52
+ http = Net::HTTP.new(uri.host, uri.port)
53
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
54
+ request.basic_auth login, password
55
+ request.body = xml_string
56
+ response = http.request(request)
57
+ if response.body.to_s == 'Access denied!'
58
+ puts "#{colorize('#############################', "red", "red")}"
59
+ puts "#{colorize('#', "red", "red")}"+"#{colorize('Incorrect Login or Password', "red")}"+ "#{colorize('#', "red", "red")}"
60
+ puts "#{colorize('#############################', "red", "red")}"
61
+ return false
62
+ else
63
+ puts "#{colorize('###########################', "green" , "green")}"
64
+ puts "#{colorize('#', "green", "green")}"+ "#{colorize('Successful Authentication', "green")}"+ "#{colorize('#', "green", "green")}"
65
+ puts "#{colorize('###########################', "green" , "green")}"
66
+ return true
67
+ end
68
+
69
+ end
28
70
 
29
71
 
30
72
  def self.test_sms(text)
@@ -1,3 +1,3 @@
1
1
  module Smsfly
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smsfly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serhii-Danovsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler