vodem_sms 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -7
- data/changelog.md +4 -0
- data/lib/vodem_sms/errors.rb +5 -0
- data/lib/vodem_sms/message.rb +30 -0
- data/lib/vodem_sms/messages.rb +40 -0
- data/lib/vodem_sms/version.rb +1 -1
- data/lib/vodem_sms.rb +16 -2
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf11adbdb4eded47edf477fb9df5016d70869202
|
4
|
+
data.tar.gz: 4a7f83ff0d44e3a347a4cd5d0876ae95832e4e79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41f9a941340487a43832455963b310a3665a3a0eb6009c6a79c336a112f82eef4f1cb82218b32a411a37d740d5a90481aa5681bdc25308f592a1b4aee4135e56
|
7
|
+
data.tar.gz: 84082425e802f807256509331b76ceb2700f20dba4345eb4a33960d92348dc0b7fba8c78c612da383113ba687d3caede1caf35d6e4d4655810ce8e73b21ddf49
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# VodemSms
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Basic gem for interfacing with a Vodafone Dongle. It's a huwaei one,
|
4
|
+
so might be useful for others too.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,13 +21,21 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
There are just a couple of commands at the moment, connect!, disconnect!. Also status info. Sample script:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'vodem_sms'
|
26
28
|
|
27
|
-
|
29
|
+
vodem = Vodem.new
|
28
30
|
|
29
|
-
|
31
|
+
vodem.connected?
|
32
|
+
vodem.disconnected?
|
33
|
+
vodem.connecting?
|
30
34
|
|
31
|
-
|
35
|
+
vodem.connect! #connect to the 3G network
|
36
|
+
vodem.disconnect! #disconnect from the 3G network
|
37
|
+
|
38
|
+
```
|
32
39
|
|
33
40
|
## Contributing
|
34
41
|
|
data/changelog.md
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module VodemSms
|
2
|
+
class Messages
|
3
|
+
class Message
|
4
|
+
attr_reader :from, :id, :sent_at, :content
|
5
|
+
|
6
|
+
def initialize(message)
|
7
|
+
@id = message["id"]
|
8
|
+
@from = message["number"]
|
9
|
+
set_date(message["date"])
|
10
|
+
set_content(message["content"])
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def set_date(date)
|
17
|
+
@sent_at ||= if /\A(?<year>\d\d),(?<month>\d\d),(?<day>\d\d),(?<hour>\d\d),(?<minute>\d\d)/ =~ date
|
18
|
+
adjusted_year = year.to_i + 2000
|
19
|
+
DateTime.strptime("#{adjusted_year}-#{month}-#{day}T#{hour}:#{minute}", '%Y-%m-%dT%H:%M')
|
20
|
+
else
|
21
|
+
Time.now
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_content(encoded_content)
|
26
|
+
@content ||= [encoded_content].pack('H*').force_encoding('utf-16be').encode('utf-8')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "vodem_sms/message"
|
2
|
+
|
3
|
+
module VodemSms
|
4
|
+
class Messages
|
5
|
+
WEBSERVER_GET_MESSAGE_URL = "http://192.168.9.1/goform/goform_get_cmd_process"
|
6
|
+
WEBSERVER_HOST_HEADER = "192.168.9.1"
|
7
|
+
AGENT_HEADER = "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0'"
|
8
|
+
LANGUAGE_HEADER= "en-US,en;q=0.5"
|
9
|
+
ENCODING_HEADER = 'gzip, deflate'
|
10
|
+
CACHE_CONTROL_HEADER = 'no-cache'
|
11
|
+
CONNECTION_HEADER = 'keep-alive'
|
12
|
+
CONTENT_TYPE_HEADER = 'application/x-www-form-urlencoded; charset=UTF-8'
|
13
|
+
PRAGMA_HEADER = 'no-cache'
|
14
|
+
X_REQUESTED_WITH_HEADER = 'XMLHttpRequest'
|
15
|
+
REFERRER_HEADER = 'http://192.168.9.1/home.htm'
|
16
|
+
|
17
|
+
def get_message
|
18
|
+
response = Typhoeus.get(
|
19
|
+
WEBSERVER_GET_MESSAGE_URL,
|
20
|
+
headers: {
|
21
|
+
Host: WEBSERVER_HOST_HEADER,
|
22
|
+
"User-Agent" => AGENT_HEADER,
|
23
|
+
"Accept-Language" => LANGUAGE_HEADER,
|
24
|
+
"Accept-Encoding" => ENCODING_HEADER,
|
25
|
+
"x-requested-with" => X_REQUESTED_WITH_HEADER,
|
26
|
+
"Referer" => REFERRER_HEADER,
|
27
|
+
Accept: "application/json"
|
28
|
+
},
|
29
|
+
params: {cmd: "sms_page_data",page: 0, data_per_page: 1, mem_store: 1, tags:12,
|
30
|
+
order_by: "order+by+id+desc"},
|
31
|
+
)
|
32
|
+
messages = JSON.parse(response.body)["messages"]
|
33
|
+
if messages.empty?
|
34
|
+
nil
|
35
|
+
else
|
36
|
+
Message.new(messages.first)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/vodem_sms/version.rb
CHANGED
data/lib/vodem_sms.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
require "vodem_sms/version"
|
2
2
|
require "vodem_sms/status_checker"
|
3
3
|
require "vodem_sms/commands"
|
4
|
+
require "vodem_sms/messages"
|
5
|
+
require "vodem_sms/errors"
|
4
6
|
require "typhoeus"
|
5
|
-
require "pry"
|
6
7
|
require "json"
|
7
8
|
|
8
9
|
module VodemSms
|
9
10
|
class Vodem
|
10
11
|
extend Forwardable
|
11
12
|
def_delegators :status, :connected?, :disconnected?, :connecting?
|
12
|
-
def_delegators :commands, :
|
13
|
+
def_delegators :commands, :disconnect!
|
14
|
+
|
15
|
+
def connect!
|
16
|
+
commands.connect! and return false if disconnected?
|
17
|
+
status
|
18
|
+
end
|
19
|
+
|
20
|
+
def latest_message
|
21
|
+
VodemSms::Messages.new.get_message
|
22
|
+
end
|
13
23
|
|
14
24
|
private
|
15
25
|
|
@@ -20,5 +30,9 @@ module VodemSms
|
|
20
30
|
def commands
|
21
31
|
Commands.new
|
22
32
|
end
|
33
|
+
|
34
|
+
def messanger
|
35
|
+
Messages.new
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vodem_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Davey
|
@@ -156,6 +156,9 @@ files:
|
|
156
156
|
- changelog.md
|
157
157
|
- lib/vodem_sms.rb
|
158
158
|
- lib/vodem_sms/commands.rb
|
159
|
+
- lib/vodem_sms/errors.rb
|
160
|
+
- lib/vodem_sms/message.rb
|
161
|
+
- lib/vodem_sms/messages.rb
|
159
162
|
- lib/vodem_sms/status_checker.rb
|
160
163
|
- lib/vodem_sms/version.rb
|
161
164
|
- vodem_sms.gemspec
|