freebox_api 0.0.1
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.
- data/.gitignore +2 -0
- data/README.md +77 -0
- data/freebox_api.gemspec +18 -0
- data/lib/freebox_api/resources/interface.rb +45 -0
- data/lib/freebox_api/resources/lan_host.rb +38 -0
- data/lib/freebox_api/resources/redir.rb +27 -0
- data/lib/freebox_api/resources/static_lease.rb +22 -0
- data/lib/freebox_api/version.rb +3 -0
- data/lib/freebox_api.rb +120 -0
- metadata +85 -0
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
Freebox OS API bindings for Ruby
|
2
|
+
================================
|
3
|
+
|
4
|
+
WARNING: Work In Progress.
|
5
|
+
|
6
|
+
Overview
|
7
|
+
--------
|
8
|
+
|
9
|
+
This gem contains Freebox OS API bindings for the Ruby language.
|
10
|
+
I started working on that to use it with https://github.com/mcanevet/puppet-freebox
|
11
|
+
|
12
|
+
Obtaining an app\_token
|
13
|
+
-----------------------
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'freebox_api'
|
17
|
+
|
18
|
+
puts FreeboxApi::Freebox.app_token('fr.freebox.testapp', 'Test App', '0.0.7', 'Pc de Xavier')
|
19
|
+
```
|
20
|
+
|
21
|
+
Initialize application
|
22
|
+
----------------------
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'freebox_api'
|
26
|
+
|
27
|
+
mafreebox = FreeboxApi::Freebox.new('dyNYgfK0Ya6FWGqq83sBHa7TwzWo+pg4fDFUJHShcjVYzTfaRrZzm93p7OTAfH/0', 'fr.freebox.testapp', 'Test App', '0.0.7', 'Pc de Xavier', 'http://mafreebox.example.com:4242')
|
28
|
+
```
|
29
|
+
|
30
|
+
Get the current challenge
|
31
|
+
-------------------------
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
puts mafreebox.challenge
|
35
|
+
```
|
36
|
+
|
37
|
+
Get the current password
|
38
|
+
------------------------
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
puts mafreebox.password
|
42
|
+
```
|
43
|
+
|
44
|
+
Get the current session\_token
|
45
|
+
-----------------------------
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
puts mafreebox.session_token
|
49
|
+
```
|
50
|
+
|
51
|
+
Get the list of browsable LAN interfaces
|
52
|
+
----------------------------------------
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
puts mafreebox.interfaces
|
56
|
+
```
|
57
|
+
|
58
|
+
Get the list of LAN hosts
|
59
|
+
-------------------------
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
puts mafreebox.lan_hosts
|
63
|
+
```
|
64
|
+
|
65
|
+
Get the list of DHCP static leases
|
66
|
+
----------------------------------
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
puts mafreebox.static_leases
|
70
|
+
```
|
71
|
+
|
72
|
+
Get the list of Port Forwardings
|
73
|
+
--------------------------------
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
puts mafreebox.redirs
|
77
|
+
```
|
data/freebox_api.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../lib/freebox_api/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Mickaël Canévet"]
|
5
|
+
gem.email = 'mickael.canevet@gmail.com'
|
6
|
+
gem.description = %q{Helps you to use Freebox OS's API calls from your app}
|
7
|
+
gem.summary = %q{Ruby bindings for Freebox OS's rest API}
|
8
|
+
gem.homepage = 'http://github.com/mcanevet/freebox_api'
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.name = 'freebox_api'
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = FreeboxApi::VERSION
|
15
|
+
|
16
|
+
gem.add_dependency 'json'
|
17
|
+
gem.add_dependency 'rest-client', '>= 1.6.1'
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module FreeboxApi
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
class Interface
|
6
|
+
|
7
|
+
attr_reader :name, :host_count
|
8
|
+
|
9
|
+
def initialize(name, host_count, freebox)
|
10
|
+
@name = name
|
11
|
+
@host_count = host_count
|
12
|
+
@freebox = freebox
|
13
|
+
end
|
14
|
+
|
15
|
+
def lan_hosts
|
16
|
+
JSON.parse(
|
17
|
+
RestClient.get(
|
18
|
+
"#{@freebox.base_url}/api/v1/lan/browser/#{@name}",
|
19
|
+
:'X_Fbx_App_Auth' => @freebox.session_token
|
20
|
+
)
|
21
|
+
)['result'].collect { |lan_host|
|
22
|
+
FreeboxApi::Resources::LanHost.new(
|
23
|
+
lan_host['id'],
|
24
|
+
lan_host['primary_name'],
|
25
|
+
lan_host['host_type'],
|
26
|
+
lan_host['primary_name_manual'],
|
27
|
+
lan_host['l2ident'],
|
28
|
+
lan_host['vendor_name '],
|
29
|
+
lan_host['persistent'],
|
30
|
+
lan_host['reachable'],
|
31
|
+
lan_host['last_time_reachable'],
|
32
|
+
lan_host['active'],
|
33
|
+
lan_host['last_activity'],
|
34
|
+
lan_host['names'],
|
35
|
+
lan_host['l3connectivities'],
|
36
|
+
self,
|
37
|
+
@freebox)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module FreeboxApi
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
class LanHost
|
6
|
+
|
7
|
+
attr_reader :id, :primary_name, :host_type, :primary_name_manual, :l2ident, :vendor_name, :persistent, :reachable, :last_time_reachable, :active, :last_activity, :names, :l3connectivities, :interface
|
8
|
+
|
9
|
+
def initialize(id, primary_name, host_type, primary_name_manual, l2ident, vendor_name, persistent, reachable, last_time_reachable, active, last_activity, names, l3connectivities, interface, freebox)
|
10
|
+
@id = id
|
11
|
+
@primary_name = primary_name
|
12
|
+
@host_type = host_type
|
13
|
+
@primary_name_manual = primary_name_manual
|
14
|
+
@l2ident = l2ident
|
15
|
+
@vendor_name = vendor_name
|
16
|
+
@persistent = persistent
|
17
|
+
@reachable = reachable
|
18
|
+
@last_time_reachable = last_time_reachable
|
19
|
+
@active = active
|
20
|
+
@last_activity = last_activity
|
21
|
+
@names = names
|
22
|
+
@l3connectivities = l3connectivities
|
23
|
+
@interface = interface
|
24
|
+
@freebox = freebox
|
25
|
+
end
|
26
|
+
|
27
|
+
def static_leases
|
28
|
+
@freebox.static_leases.select { |static_lease|
|
29
|
+
static_lease.host == self
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module FreeboxApi
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
class Redir
|
6
|
+
|
7
|
+
attr_reader :id, :enabled, :ip_proto, :wan_port_start, :wan_port_end, :lan_ip, :lan_port, :hostname, :host, :comment
|
8
|
+
|
9
|
+
def initialize(id, enabled, ip_proto, wan_port_start, wan_port_end, lan_ip, lan_port, hostname, host, comment, freebox)
|
10
|
+
@id = id
|
11
|
+
@enabled = enabled
|
12
|
+
@ip_proto = ip_proto
|
13
|
+
@wan_port_start = wan_port_start
|
14
|
+
@wan_port_end = wan_port_end
|
15
|
+
@lan_ip = lan_ip
|
16
|
+
@lan_port = lan_port
|
17
|
+
@hostname = hostname
|
18
|
+
@host = host
|
19
|
+
@comment = comment
|
20
|
+
@freebox = freebox
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FreeboxApi
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
class StaticLease
|
6
|
+
|
7
|
+
attr_reader :id, :mac, :comment, :hostname, :ip, :host
|
8
|
+
|
9
|
+
def initialize(id, mac, comment, hostname, ip, host, freebox)
|
10
|
+
@id = id
|
11
|
+
@mac = mac
|
12
|
+
@hostname = hostname
|
13
|
+
@ip = ip
|
14
|
+
@host = host
|
15
|
+
@freebox = freebox
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/freebox_api.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module FreeboxApi
|
5
|
+
|
6
|
+
class Freebox
|
7
|
+
|
8
|
+
attr_reader :app_token, :app_id, :app_name, :app_version, :device_name, :base_url
|
9
|
+
|
10
|
+
def initialize(app_token, app_id, app_name, app_version, device_name, base_url = 'http://mafreebox.free.fr')
|
11
|
+
@app_id = app_id
|
12
|
+
@app_name = app_name
|
13
|
+
@app_version = app_version
|
14
|
+
@device_name = device_name
|
15
|
+
@app_token = app_token
|
16
|
+
@base_url = base_url
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.app_token(app_id, app_name, app_version, device_name)
|
20
|
+
JSON.parse(RestClient.post(
|
21
|
+
"#{@base_url}/api/v1/login/authorize",
|
22
|
+
{
|
23
|
+
:app_id => app_id,
|
24
|
+
:app_name => app_name,
|
25
|
+
:app_version => app_version,
|
26
|
+
:device_name => device_name,
|
27
|
+
}.to_json,
|
28
|
+
:content_type => :json,
|
29
|
+
:accept => :json
|
30
|
+
))['result']['app_token']
|
31
|
+
end
|
32
|
+
|
33
|
+
def challenge
|
34
|
+
JSON.parse(RestClient.get("#{@base_url}/api/v1/login/"))['result']['challenge']
|
35
|
+
end
|
36
|
+
|
37
|
+
def password
|
38
|
+
Digest::HMAC.hexdigest(challenge, @app_token, Digest::SHA1)
|
39
|
+
end
|
40
|
+
|
41
|
+
def session_token
|
42
|
+
JSON.parse(
|
43
|
+
RestClient.post(
|
44
|
+
"#{@base_url}/api/v1/login/session/",
|
45
|
+
{
|
46
|
+
:app_id => @app_id,
|
47
|
+
:password => password,
|
48
|
+
}.to_json,
|
49
|
+
:content_type => :json,
|
50
|
+
:accept => :json
|
51
|
+
)
|
52
|
+
)['result']['session_token']
|
53
|
+
end
|
54
|
+
|
55
|
+
def interfaces
|
56
|
+
JSON.parse(
|
57
|
+
RestClient.get(
|
58
|
+
"#{@base_url}/api/v1/lan/browser/interfaces",
|
59
|
+
:'X_Fbx_App_Auth' => session_token
|
60
|
+
)
|
61
|
+
)['result'].collect { |interface|
|
62
|
+
FreeboxApi::Resources::Interface.new(interface['name'], interface['host_count'], self)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
def lan_hosts
|
67
|
+
interfaces.collect { |interface|
|
68
|
+
interface.lan_hosts
|
69
|
+
}.flatten
|
70
|
+
end
|
71
|
+
|
72
|
+
def static_leases
|
73
|
+
JSON.parse(
|
74
|
+
RestClient.get(
|
75
|
+
"#{@base_url}/api/v1/dhcp/static_lease/",
|
76
|
+
:'X_Fbx_App_Auth' => session_token
|
77
|
+
)
|
78
|
+
)['result'].collect { |static_lease|
|
79
|
+
FreeboxApi::Resources::StaticLease.new(
|
80
|
+
static_lease['id'],
|
81
|
+
static_lease['mac'],
|
82
|
+
static_lease['comment'],
|
83
|
+
static_lease['hostname'],
|
84
|
+
static_lease['ip'],
|
85
|
+
lan_hosts.select { |lan_host| lan_host.id == static_lease['host']['id'] },
|
86
|
+
self
|
87
|
+
)
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def redirs
|
92
|
+
JSON.parse(
|
93
|
+
RestClient.get(
|
94
|
+
"#{@base_url}/api/v1/fw/redir/",
|
95
|
+
:'X_Fbx_App_Auth' => session_token
|
96
|
+
)
|
97
|
+
)['result'].collect { |redir|
|
98
|
+
FreeboxApi::Resources::Redir.new(
|
99
|
+
redir['id'],
|
100
|
+
redir['enabled'],
|
101
|
+
redir['ip_proto'],
|
102
|
+
redir['wan_port_start'],
|
103
|
+
redir['wan_port_end'],
|
104
|
+
redir['lan_ip'],
|
105
|
+
redir['lan_port'],
|
106
|
+
redir['hostname'],
|
107
|
+
lan_hosts.select { |lan_host| lan_host.id == redir['host']['id'] },
|
108
|
+
redir['comment'],
|
109
|
+
self
|
110
|
+
)
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
require 'freebox_api/version'
|
119
|
+
resource_files = Dir[File.expand_path("#{File.dirname(__FILE__)}/freebox_api/resources/*.rb", __FILE__)]
|
120
|
+
resource_files.each { |f| require f }
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: freebox_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mickaël Canévet
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rest-client
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.6.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.1
|
46
|
+
description: Helps you to use Freebox OS's API calls from your app
|
47
|
+
email: mickael.canevet@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- README.md
|
54
|
+
- freebox_api.gemspec
|
55
|
+
- lib/freebox_api.rb
|
56
|
+
- lib/freebox_api/resources/interface.rb
|
57
|
+
- lib/freebox_api/resources/lan_host.rb
|
58
|
+
- lib/freebox_api/resources/redir.rb
|
59
|
+
- lib/freebox_api/resources/static_lease.rb
|
60
|
+
- lib/freebox_api/version.rb
|
61
|
+
homepage: http://github.com/mcanevet/freebox_api
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.23
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Ruby bindings for Freebox OS's rest API
|
85
|
+
test_files: []
|