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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5176b4aac23ede9ff330081f287e4e6e93fda884
4
- data.tar.gz: 149184c916dd31cab504eea5e6a65ca8a7bfa192
3
+ metadata.gz: cf11adbdb4eded47edf477fb9df5016d70869202
4
+ data.tar.gz: 4a7f83ff0d44e3a347a4cd5d0876ae95832e4e79
5
5
  SHA512:
6
- metadata.gz: cd0cd09f9ba20c4caf8f913df90594bbf44253f0a570bc7f2ef5614f77818296d8406fa4ab0b16ad2af2fa424b37690513dfc492a4945dc8fcd300325321596a
7
- data.tar.gz: 16b3001ea548acda6c35e3e6bf874b80c1b5df7b89b3c7675e4462efb35152825f2de8e00027dfd4ca3f8965bd8425af34eee6f47ed7d840cb7c13b088ba2740
6
+ metadata.gz: 41f9a941340487a43832455963b310a3665a3a0eb6009c6a79c336a112f82eef4f1cb82218b32a411a37d740d5a90481aa5681bdc25308f592a1b4aee4135e56
7
+ data.tar.gz: 84082425e802f807256509331b76ceb2700f20dba4345eb4a33960d92348dc0b7fba8c78c612da383113ba687d3caede1caf35d6e4d4655810ce8e73b21ddf49
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # VodemSms
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vodem_sms`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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
- ## Development
29
+ vodem = Vodem.new
28
30
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
31
+ vodem.connected?
32
+ vodem.disconnected?
33
+ vodem.connecting?
30
34
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
@@ -1,3 +1,7 @@
1
+ ## 0.0.2 [April 2015]
2
+
3
+ * Add the ability to Read the latest SMS off the vodem
4
+
1
5
  ## 0.0.1 [April 2015]
2
6
 
3
7
  * Initial beta release of the vodem_sms gem.
@@ -0,0 +1,5 @@
1
+ module VodemSms
2
+ module Errors
3
+ NotConnectedError = Class.new(StandardError)
4
+ end
5
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module VodemSms
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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, :connect!, :disconnect!
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.1
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