freebox_api 0.1.1 → 0.1.2

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
+ OWU0Zjg4MjY4Yjk3ZTFkNGZkMjY1MmJmOTM2NzNhNTIwNTU1ZTI0Mg==
5
+ data.tar.gz: !binary |-
6
+ MzM3ODk1MWMwZjg0NzZiYmUzMWRiY2JjNDZlYmEyMGZlZTc4NDk1YQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWE3ZTk4ODZhYjMxNGEyOTMyOTM3ZjVlY2ZjZGZmMTAwMzUyMThlNTUzOGQz
10
+ M2QwYTdhMzQwZmNhZTUwNTcyZGJjNjlmZmMzNjg2OGVlZTExMTU3YzU1NWZj
11
+ OTFmOTY1NjU1OWU1NWZmOGI3ZGJhNDY1OTY5MTQxODY3M2ViZTg=
12
+ data.tar.gz: !binary |-
13
+ MGI5ZGViOGViYmYxMTZhZTIxYjk3NmExODZhYjQ4NGYyNTZjNjMyYWZkZTY2
14
+ MTQyMWZkZjRlM2E3NTdmMjgyOGRjZThmY2Y0NjY1OTc0MTA5NTgyYjBhZDYz
15
+ YzE4MjIyMzJhODY1ZGQ1NzlmZDBlMzc4ODA3ZTM2NTRjY2EwNDE=
@@ -3,6 +3,7 @@ module FreeboxApi
3
3
  class Config
4
4
 
5
5
  def initialize(session)
6
+ @session = session
6
7
  end
7
8
 
8
9
  def url(service)
@@ -21,11 +22,11 @@ module FreeboxApi
21
22
  end
22
23
 
23
24
  def show(service)
24
- @session.http_call('get', url)
25
+ @session.http_call('get', url(service))
25
26
  end
26
27
 
27
28
  def update(service, params = {})
28
- @session.http_call('put', url, params)
29
+ @session.http_call('put', url(service), params)
29
30
  end
30
31
 
31
32
  end
@@ -1,10 +1,13 @@
1
1
  require 'rest_client'
2
2
  require 'json'
3
+ require 'logger'
3
4
 
4
5
  module FreeboxApi
5
6
 
6
7
  class Freebox < Hash
7
8
 
9
+ attr_reader :logger
10
+
8
11
  def initialize(hash = {})
9
12
  self[:freebox_ip] = hash[:freebox_ip] ? hash[:freebox_ip] : 'mafreebox.free.fr'
10
13
  self[:freebox_port] = hash[:freebox_port] ? hash[:freebox_port] : '80'
@@ -14,8 +17,17 @@ module FreeboxApi
14
17
  self[:api_version] = discover['api_version']
15
18
  self[:api_base_url] = discover['api_base_url']
16
19
  self[:device_type] = discover['device_type']
20
+ self.logger = nil
17
21
  end
18
22
 
23
+ def logger=(logger)
24
+ if logger.nil?
25
+ logger = Logger.new(STDOUT)
26
+ logger.level = Logger::WARN
27
+ end
28
+ @logger = logger
29
+ end
30
+
19
31
  def discover
20
32
  args = ['get']
21
33
  @discover ||= JSON.parse(@client['/api_version'].send(*args))
@@ -37,7 +49,7 @@ module FreeboxApi
37
49
  http_call('get', '/login/')['challenge']
38
50
  end
39
51
 
40
- def http_call(http_method, path, params = {}, session = nil)
52
+ def http_call(http_method, path, params = nil, session = nil)
41
53
  headers = {}
42
54
 
43
55
  args = [http_method]
@@ -47,8 +59,22 @@ module FreeboxApi
47
59
  headers[:params] = params if params
48
60
  end
49
61
  headers[:'X_Fbx_App_Auth'] = session.session_token if session
62
+
63
+ logger.info "#{http_method.upcase} #{path}"
64
+ logger.debug "Params: #{params.inspect}"
65
+ logger.debug "Headers: #{headers.inspect}"
50
66
  args << headers if headers
51
- JSON.parse(@client[build_url(path)].send(*args))['result']
67
+ process_data(@client[build_url(path)].send(*args))['result']
68
+ end
69
+
70
+ def process_data(response)
71
+ data = begin
72
+ JSON.parse(response.body)
73
+ rescue JSON::ParserError
74
+ response.body
75
+ end
76
+ logger.debug "Returned data: #{data.inspect}"
77
+ return data
52
78
  end
53
79
 
54
80
  end
@@ -9,7 +9,7 @@ module FreeboxApi
9
9
  end
10
10
 
11
11
  def index
12
- @session.http_call('get', '/dhcp/static_lease/')
12
+ @session.http_call('get', '/dhcp/static_lease/') || []
13
13
  end
14
14
 
15
15
  def show(id)
@@ -1,3 +1,3 @@
1
1
  module FreeboxApi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,61 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: freebox_api
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
11
5
  platform: ruby
12
- authors:
13
- - "Micka\xC3\xABl Can\xC3\xA9vet"
6
+ authors:
7
+ - Mickaël Canévet
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2013-09-30 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: json
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
32
20
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rest-client
36
21
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 13
43
- segments:
44
- - 1
45
- - 6
46
- - 1
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
47
33
  version: 1.6.1
48
34
  type: :runtime
49
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.1
50
41
  description: Helps you to use Freebox OS's API calls from your app
51
42
  email: mickael.canevet@gmail.com
52
43
  executables: []
53
-
54
44
  extensions: []
55
-
56
45
  extra_rdoc_files: []
57
-
58
- files:
46
+ files:
59
47
  - .gitignore
60
48
  - LICENSE
61
49
  - README.md
@@ -74,37 +62,27 @@ files:
74
62
  - lib/freebox_api/session.rb
75
63
  - lib/freebox_api/version.rb
76
64
  homepage: http://github.com/mcanevet/freebox_api
77
- licenses:
65
+ licenses:
78
66
  - Apache 2.0
67
+ metadata: {}
79
68
  post_install_message:
80
69
  rdoc_options: []
81
-
82
- require_paths:
70
+ require_paths:
83
71
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
102
82
  requirements: []
103
-
104
83
  rubyforge_project:
105
- rubygems_version: 1.8.24
84
+ rubygems_version: 2.1.5
106
85
  signing_key:
107
- specification_version: 3
86
+ specification_version: 4
108
87
  summary: Ruby bindings for Freebox OS's rest API
109
88
  test_files: []
110
-