rbchannels 0.1.0 → 1.0.0

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: 8804c079ed7a2f048251b4d7e71ea23c2e41d495
4
- data.tar.gz: 53a474490f5fe1755af2814f8d511b2db57fb5ef
3
+ metadata.gz: '08d0c261b21933a1d7b686c91f85add22cea52ac'
4
+ data.tar.gz: 85a1d2df27029d33a849ce76a55d61653ca8df76
5
5
  SHA512:
6
- metadata.gz: 74d89d9f99ac889f24c5c0531ec96ec4621d87d85da1c56ee43b324331f319a02e6c98cef7625ee06acb6c9bdb57d625dcdb2e9e0b273734fa9aff0b87155e9f
7
- data.tar.gz: 17a7a1e98dce49d15f206d594235ee38770c1813d1b55615b37989258238b0d06dbeac8574ba79ccc172523fae0c5ae9d6a8e334f634d54983e8cf9650fb2bd2
6
+ metadata.gz: bed0ca00b4238efc83e8e2a71b495e7f126cbed69d8cc49f3cb3db4d119f17161d5d4eb8e4ce1fe2c67d46d2d6d56dcc54ee78dc17db4bfef489373e446f825b
7
+ data.tar.gz: ab311b0a8451715a6cff4f65916e5d8abbe60cc272d1e7089b7a0e737999f55130ec636fce73acc664d725acb33c3dcffce6961fdedf96f1554676cd24f49bdb
data/lib/rbchannels.rb ADDED
@@ -0,0 +1,100 @@
1
+ require 'rbchannels/version'
2
+ require 'httparty'
3
+
4
+ class Channels::Client
5
+ include HTTParty
6
+ default_timeout 2
7
+ format :json
8
+
9
+ def initialize(host, port=57000)
10
+ self.class.base_uri "http://#{host}:#{port}/api"
11
+ end
12
+
13
+ def status
14
+ request("GET", "/status")
15
+ end
16
+
17
+ def favorite_channels
18
+ request("GET", "/favorite_channels")
19
+ if response.is_a?(Array)
20
+ response
21
+ else
22
+ []
23
+ end
24
+ end
25
+
26
+ def pause
27
+ command('pause')
28
+ end
29
+
30
+ def resume
31
+ command('resume')
32
+ end
33
+
34
+ def stop
35
+ command('stop')
36
+ end
37
+
38
+ def seek(seconds=0)
39
+ command("seek/#{seconds}")
40
+ end
41
+
42
+ def seek_forward
43
+ command('seek_forward')
44
+ end
45
+
46
+ def seek_backward
47
+ command('seek_backward')
48
+ end
49
+
50
+ def skip_forward
51
+ command('skip_forward')
52
+ end
53
+
54
+ def skip_backward
55
+ command('skip_backward')
56
+ end
57
+
58
+ def toggle_mute
59
+ command('toggle_mute')
60
+ end
61
+
62
+ def play_channel(channel_number)
63
+ command("play/channel/#{channel_number}")
64
+ end
65
+
66
+ def play_recording(recording_id)
67
+ command("play/recording/#{recording_id}")
68
+ end
69
+
70
+
71
+ private
72
+
73
+ def request(method, path)
74
+ begin
75
+ case method
76
+ when "GET"
77
+ response = self.class.get(path)
78
+ when "POST"
79
+ response = self.class.post(path)
80
+ when "PUT"
81
+ response = self.class.put(path)
82
+ when "DELETE"
83
+ response = self.class.delete(path)
84
+ end
85
+
86
+ if response
87
+ response.parsed_response
88
+ else
89
+ {'status': 'error'}
90
+ end
91
+ rescue
92
+ {'status': 'error'}
93
+ end
94
+ end
95
+
96
+ def command(named_command)
97
+ return request('POST', '/' + named_command)
98
+ end
99
+
100
+ end
@@ -0,0 +1,3 @@
1
+ module Channels
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'minitest/autorun'
2
+ require 'rbchannels'
3
+
4
+ class ChannelsTest < Minitest::Test
5
+
6
+ def test_base_uri
7
+ client = Channels::Client.new("192.168.1.50", 8888)
8
+ assert_equal "http://192.168.1.50:8888/api", client.class.base_uri
9
+ end
10
+
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbchannels
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Maddox
@@ -29,7 +29,10 @@ email: jon@getchannels.com
29
29
  executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
- files: []
32
+ files:
33
+ - lib/rbchannels.rb
34
+ - lib/rbchannels/version.rb
35
+ - test/test_channels.rb
33
36
  homepage: https://github.com/fancybits/rbchannels
34
37
  licenses:
35
38
  - MIT
@@ -54,4 +57,5 @@ rubygems_version: 2.6.13
54
57
  signing_key:
55
58
  specification_version: 4
56
59
  summary: API client for the Channels app - https://getchannels.com
57
- test_files: []
60
+ test_files:
61
+ - test/test_channels.rb