neura-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/neura-client.rb +49 -0
- data/lib/neura-client/authenticator.rb +23 -0
- data/lib/neura-client/device.rb +36 -0
- data/lib/neura-client/pending_action.rb +32 -0
- data/lib/neura-client/speaker_of_the_house.rb +13 -0
- data/lib/neura-client/version.rb +5 -0
- data/neura-client.gemspec +20 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tom Caspy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Neura::Client
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'neura-client'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install neura-client
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/neura-client.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "neura-client/version"
|
2
|
+
require "neura-client/authenticator"
|
3
|
+
require "neura-client/pending_action"
|
4
|
+
require "neura-client/device"
|
5
|
+
|
6
|
+
module Neura
|
7
|
+
module Client
|
8
|
+
HOST="http://neura.dev"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def authenticator
|
12
|
+
@authenticator ||= Authenticator.new(email: email, password: password)
|
13
|
+
end
|
14
|
+
|
15
|
+
def headers
|
16
|
+
@headers ||= {
|
17
|
+
'Authorization' => 'Bearer ' + access_token,
|
18
|
+
'Accept-Language' => 'en-us',
|
19
|
+
'Connection' => 'keep-alive',
|
20
|
+
'Accept' => 'application/json'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def email=(email)
|
25
|
+
@email = email
|
26
|
+
end
|
27
|
+
|
28
|
+
def email
|
29
|
+
@email || "tcaspy@gmail.com"
|
30
|
+
end
|
31
|
+
|
32
|
+
def password=(password)
|
33
|
+
@password = password
|
34
|
+
end
|
35
|
+
|
36
|
+
def password
|
37
|
+
@password || "1234"
|
38
|
+
end
|
39
|
+
|
40
|
+
def access_token=(token)
|
41
|
+
@access_token = token
|
42
|
+
end
|
43
|
+
|
44
|
+
def access_token
|
45
|
+
@access_token ||= authenticator.access_token
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module Neura
|
4
|
+
module Client
|
5
|
+
class Authenticator
|
6
|
+
|
7
|
+
attr_accessor :access_token
|
8
|
+
|
9
|
+
def initialize(params = {})
|
10
|
+
@access_token = params[:token]
|
11
|
+
unless @access_token
|
12
|
+
@access_token = fetch_token(params)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch_token(params)
|
17
|
+
result = HTTParty.post("#{Neura::Client::HOST}/external_api/v1/auth.json", body: params)
|
18
|
+
result["token"]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Neura
|
2
|
+
module Client
|
3
|
+
class Device
|
4
|
+
|
5
|
+
def initialize(device_id, device)
|
6
|
+
@id = device_id
|
7
|
+
@device = device
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_attributes(attributes)
|
11
|
+
HTTParty.post("#{Neura::Client::HOST}/external_api/v1/nodes/#{@id}/update", body: {attributes: attributes}, headers: Neura::Client.headers)
|
12
|
+
end
|
13
|
+
|
14
|
+
def fire_event(event = {})
|
15
|
+
HTTParty.post("#{Neura::Client::HOST}/external_api/v1/nodes/#{@id}/event", body: {event: attributes}, headers: Neura::Client.headers)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_pending_actions
|
19
|
+
result = HTTParty.get("#{Neura::Client::HOST}/external_api/v1/nodes/#{@id}/pending_actions", headers: Neura::Client.headers)
|
20
|
+
[*result["pending_actions"]].map{|pa| Neura::Client::PendingAction.new(pa["pending_action"])}
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform_pending_actions
|
24
|
+
actions = get_pending_actions
|
25
|
+
actions.each do |action|
|
26
|
+
if @device.perform!(action)
|
27
|
+
action.done!
|
28
|
+
else
|
29
|
+
action.reject!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Neura
|
2
|
+
module Client
|
3
|
+
class PendingAction
|
4
|
+
|
5
|
+
attr_accessor :id, :command, :payload
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
@id = params["id"]
|
9
|
+
@command = params["command"]
|
10
|
+
@status = params["status"]
|
11
|
+
@payload = params["payload"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_status(status)
|
15
|
+
HTTParty.post("#{Neura::Client::HOST}/external_api/v1/nodes/#{@id}/update_action", body: {status: status}, headers: Neura::Client.headers)
|
16
|
+
end
|
17
|
+
|
18
|
+
def done!
|
19
|
+
set_status(:done)
|
20
|
+
end
|
21
|
+
|
22
|
+
def reject!
|
23
|
+
set_status(:rejected)
|
24
|
+
end
|
25
|
+
|
26
|
+
def stale!
|
27
|
+
set_status(:stale)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'neura-client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "neura-client"
|
8
|
+
gem.version = Neura::Client::VERSION
|
9
|
+
gem.authors = ["Tom Caspy"]
|
10
|
+
gem.email = ["tcaspy@gmail.com"]
|
11
|
+
gem.description = %q{Neura client is a ruby client for the neura's custom device api}
|
12
|
+
gem.summary = %q{Using this gem allows easy integration with the neura in order to implement a custom device controller.}
|
13
|
+
gem.homepage = "http://client.theneura.com"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency "httparty", "~> 0.8.3"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: neura-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Caspy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
prerelease: false
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.3
|
22
|
+
none: false
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.8.3
|
29
|
+
none: false
|
30
|
+
description: Neura client is a ruby client for the neura's custom device api
|
31
|
+
email:
|
32
|
+
- tcaspy@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/neura-client.rb
|
43
|
+
- lib/neura-client/authenticator.rb
|
44
|
+
- lib/neura-client/device.rb
|
45
|
+
- lib/neura-client/pending_action.rb
|
46
|
+
- lib/neura-client/speaker_of_the_house.rb
|
47
|
+
- lib/neura-client/version.rb
|
48
|
+
- neura-client.gemspec
|
49
|
+
homepage: http://client.theneura.com
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
none: false
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
none: false
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Using this gem allows easy integration with the neura in order to implement
|
73
|
+
a custom device controller.
|
74
|
+
test_files: []
|
75
|
+
has_rdoc:
|