bravtroller 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e5a2d9ff7a5bd2ea66e36a38c24a53a03d93cd9
4
- data.tar.gz: c8ee0410e7171bb40b079c6b9bdc4ebe537bddf6
3
+ metadata.gz: 1c2771970023d32fc31b1b5f6d886604b66de45e
4
+ data.tar.gz: 48223252de5d5a1159c952e12a3239d38936b0a8
5
5
  SHA512:
6
- metadata.gz: bfcd5c7408e4adfe6dfb24c6bc917f5646c7830749c36498c6c8aa1b5bc2886ff64691e57476f06873dc164b4bf554d6e94741b074690e6921997d84e4814235
7
- data.tar.gz: dca6881a1a3060ba680e3b888c948955e771224f3187f44084951917ea8193e307bb40793c5df2759228d954f9a4b6608cf23114e89668b8d6e9cbdb76fb7819
6
+ metadata.gz: 669b812f605adfa512d048a9990e76f3861d6c507ce478d4009a645f3d704e73ee0616fd743571995c520a5a4ae496841edaca1c2ecc8fdc5b6617d1e3b40ec9
7
+ data.tar.gz: 4637c6a8e1404b77a92a589a526f70b9642106c809a359b3293465712a916d114643471514ef20987ddb9a707b2573995a33e681ef66b8e9439219cbfd81f93e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bravtroller (0.1.0)
4
+ bravtroller (0.1.1)
5
5
  easy_upnp
6
6
 
7
7
  GEM
@@ -1,3 +1,4 @@
1
+ require 'singleton'
1
2
  require 'easy_upnp/ssdp_searcher'
2
3
 
3
4
  require_relative 'authenticator'
@@ -14,30 +15,38 @@ module Bravtroller
14
15
  version: '1.0'
15
16
  }
16
17
 
17
- def self.create(bravia_client)
18
- searcher = EasyUpnp::SsdpSearcher.new
19
- results = searcher.search(IRCC_URN)
20
- authenticator = Bravtroller::Authenticator.new(bravia_client)
21
-
22
- if ! authenticator.authorized?
23
- raise RuntimeError.new 'Not authorized yet. Please authorize Bravtroller using Bravtroller::Authenticator.'
18
+ class IrccClientFactory
19
+ def initialize(client)
20
+ @client = client
24
21
  end
25
22
 
26
- if results.empty?
27
- raise RuntimeError.new "Couldn't find any UPnP devices on the network that looks like a supported Sony device"
28
- elsif results.count != 1
29
- raise RuntimeError.new "Found more than one supported Sony device. Please construct Remote manually. Found devices: #{results.inspect}"
30
- else
31
- device = results.first
32
- ircc_client = device.service(IRCC_URN, cookies: HTTPI::Cookie.new(authenticator.authorize {}))
33
-
34
- Remote.new(ircc_client, bravia_client)
23
+ def create
24
+ if @ircc_client.nil?
25
+ searcher = EasyUpnp::SsdpSearcher.new
26
+ results = searcher.search(IRCC_URN)
27
+ authenticator = Bravtroller::Authenticator.new(@client)
28
+
29
+ if !authenticator.authorized?
30
+ raise RuntimeError.new 'Not authorized yet. Please authorize Bravtroller using Bravtroller::Authenticator.'
31
+ end
32
+
33
+ if results.empty?
34
+ raise RuntimeError.new "Couldn't find any UPnP devices on the network that looks like a supported Sony device"
35
+ elsif results.count != 1
36
+ raise RuntimeError.new "Found more than one supported Sony device. Please construct Remote manually. Found devices: #{results.inspect}"
37
+ else
38
+ device = results.first
39
+ @ircc_client = device.service(IRCC_URN, cookies: HTTPI::Cookie.new(authenticator.authorize {}))
40
+ end
41
+ end
42
+
43
+ @ircc_client
35
44
  end
36
45
  end
37
46
 
38
- def initialize(ircc_client, bravia_client)
39
- @ircc_client = ircc_client
47
+ def initialize(bravia_client, ircc_client_factory = IrccClientFactory.new(bravia_client))
40
48
  @bravia_client = bravia_client
49
+ @ircc_client_factory = ircc_client_factory
41
50
  end
42
51
 
43
52
  def power_on
@@ -53,7 +62,7 @@ module Bravtroller
53
62
  def press_button(button_key)
54
63
  raise RuntimeError.new "Undefined button: #{button_key}" if ircc_codes[button_key].nil?
55
64
 
56
- @ircc_client.X_SendIRCC IRCCCode: ircc_codes[button_key]
65
+ @ircc_client_factory.create.X_SendIRCC IRCCCode: ircc_codes[button_key]
57
66
  end
58
67
 
59
68
  def buttons
@@ -1,3 +1,3 @@
1
1
  module Bravtroller
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bravtroller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mullins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-11 00:00:00.000000000 Z
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: easy_upnp