mosesacs-sdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWUwNjFiOGExODFjMWVkMTIyNzJhMzVkOGJlMzY4NjIwMzI0ZjNjNQ==
5
+ data.tar.gz: !binary |-
6
+ Mzg0MzA0YTEyZDQyZjY2YTM3MWQ1NmU0ZWQ2OTkxMDFlOWRmYzlmYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YWQ0YmM4NzY0ZjNlZmNhMmRmZTg2MDg1NzIwZWZmNDFkNzBiNmEwODMyYWY0
10
+ NGI1Mjk1NzZhNWYwMDBiYTc0ZWM5MGM4YWQ0MThjYWNhZTlmMzczZWZiOTFj
11
+ NjZiMzk2NTI2NjVjZjVmNDlhZDYyZmE1ZDY1NzdhMzAyZGFjMWI=
12
+ data.tar.gz: !binary |-
13
+ YTI1NzNiYjkwMTQ1ZTkzZDU5OGRhNmM3OWU0ZThiMWE2YWNkZjk3ZTc2ODM5
14
+ MjA2MTJkMzUyODQ2ZTc1MjhkMzEyYzFiZTZlODY0MGRhOTE1YzY4ZjAwODli
15
+ NWFkMzM0OGVkNjBlOTE0Y2JiMWEzZjJjNjAxMzk0MjQ5ZDJhNmE=
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2014-2016 Luca Cervasio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Ruby SDK to connect to MosesACS (http://mosesacs.org).
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require '../lib/mosesacs_sdk'
4
+
5
+ serial = 'A54FD'
6
+
7
+ conn = MosesacsSdk::Client.new 'localhost', '9292'
8
+ conn.ChangeDuState(serial, [
9
+ {"type" => "update", "url" => "http://url/path", "uuid" => "AAA", "username" => "user", "password" => "pass", "version" => "0.0.2"},
10
+ {"type" => "install", "url" => "http://url/path2", "uuid" => "BBB", "username" => "user", "password" => "pass", "environment" => "env"},
11
+ {"type" => "install", "url" => "http://url/path3", "uuid" => "", "username" => "user", "password" => "pass", "environment" => "env"},
12
+ {"type" => "uninstall", "version" => "0.0.1", "uuid" => "VVV", "environment" => "env"}
13
+ ])
14
+
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mosesacs_sdk'
4
+
5
+ serial = ARGV[0] || "00507F5FC268"
6
+ leaf = ARGV[1] || "InternetGatewayDevice.DeviceInfo."
7
+
8
+ conn = MosesacsSdk::Client.new 'cwmp.mosesacs.org', '9292'
9
+ conn.GetParameterValues serial, leaf
@@ -0,0 +1,76 @@
1
+ require 'faye/websocket'
2
+ require 'eventmachine'
3
+ require 'json'
4
+ require 'nokogiri'
5
+
6
+ Thread::abort_on_exception = true
7
+
8
+ module MosesacsSdk
9
+
10
+ class Client
11
+
12
+ def initialize host, port=80
13
+ @q = Queue.new
14
+ @t = Thread.new do
15
+ EM.run {
16
+ scheme = 'ws'
17
+ url = "ws://#{host}:#{port}/api"
18
+ headers = {'Origin' => 'http://localhost'}
19
+ @ws = Faye::WebSocket::Client.new(url, nil, :headers => headers)
20
+
21
+ @ws.onopen = lambda do |event|
22
+ # p [:open]
23
+ # @ws.send({"Cmd" => "readMib 00507F5FC268 InternetGatewayDevice.Time."}.to_json)
24
+ @q.push("ready")
25
+ end
26
+
27
+ @ws.onmessage = lambda do |event|
28
+ # p [:message, event.data]
29
+ d = JSON.parse(event.data)
30
+ if d["Cmd"] =~ /soap/
31
+ @q.push d["Cmd"]
32
+ else
33
+ # ignore logs
34
+ puts d['reason']
35
+ @q.push ""
36
+ end
37
+
38
+ # ws.close 1002, 'Going away'
39
+ end
40
+
41
+ @ws.onclose = lambda do |event|
42
+ # p [:close, event.code, event.reason]
43
+ # puts "disconnected"
44
+ EM.stop
45
+ exit 1
46
+ end
47
+ }
48
+ end
49
+ @q.pop
50
+ # puts "Connected..."
51
+ end
52
+
53
+ def GetParameterValues (serial, leaf)
54
+ @ws.send({"Cmd" => "readMib #{serial} #{leaf}"}.to_json)
55
+ resp = @q.pop
56
+
57
+ doc = Nokogiri::XML(resp)
58
+ message_type = doc.css("soap|Body").children.map(&:name)[1]
59
+ if message_type == "Fault"
60
+ raise "Got Fault Message: #{doc.css("FaultString")[0].text}"
61
+ end
62
+
63
+ doc.css("ParameterValueStruct").each do |par|
64
+ puts "#{par.children[1].text}: #{par.children[3].text}"
65
+ end
66
+ end
67
+
68
+ def ChangeDuState (serial, ops)
69
+ @ws.send({"MsgType" => "command", "Data" => {"command" => "changeDuState #{serial}", "ops" => ops}}.to_json)
70
+ resp = @q.pop
71
+ puts resp if resp != ""
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,20 @@
1
+
2
+
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'mosesacs-sdk'
6
+ spec.version = '0.0.1'
7
+ spec.date = Date.today.to_s
8
+ spec.summary = "Mosesacs Sdk Library"
9
+ spec.description = "Library to connect to mosesacs daemon (http://mosesacs.org)"
10
+ spec.authors = ["Luca Cervasio"]
11
+ spec.email = 'luca.cervasio@gmail.com'
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.homepage = 'https://github.com/lucacervasio/mosesacs-sdk'
15
+ spec.license = 'MIT'
16
+
17
+ spec.add_dependency('nokogiri', '~> 1.6', '>= 1.6.0')
18
+ spec.add_dependency('faye-websocket', '~> 0.9', '>= 0.9.2')
19
+ spec.add_dependency('eventmachine', '~> 1.0', '>= 1.0.7')
20
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mosesacs-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luca Cervasio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: faye-websocket
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '0.9'
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 0.9.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: eventmachine
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.7
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 1.0.7
73
+ description: Library to connect to mosesacs daemon (http://mosesacs.org)
74
+ email: luca.cervasio@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - examples/change_du_state.rb
84
+ - examples/readmib.rb
85
+ - lib/mosesacs_sdk.rb
86
+ - mosesacs-sdk.gemspec
87
+ homepage: https://github.com/lucacervasio/mosesacs-sdk
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Mosesacs Sdk Library
111
+ test_files: []