ticktok-cli 0.1.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/app.rb +69 -0
  3. metadata +42 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6667890d3ba9eccc8c41a461cb1def2d3477fb0d6d7f4f263c4edb5b62182c06
4
+ data.tar.gz: 118b9aca60070894fb626441c2e30ddbc6fb3739513f81d9fd96f43f7baf3b81
5
+ SHA512:
6
+ metadata.gz: 9c0b2df81d6a89f337c8942f6a51d5f60d2a3e7d22998a2f06d01388e45bcf7415c6dbe7bc908e2e48b7bc0c619796c2118f27a66741eb20d2c5469241a1ccc7
7
+ data.tar.gz: 69e61ebb4fccd50a375b4214e51f8bf5feaab8be5dfbe98a7413643471006dd2895e637a905451dbd51605ad5642cf6a24b4214c165691fbb292b6d03a6151bb
data/lib/app.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'thor'
2
+ require 'bunny'
3
+ require 'rest-client'
4
+ require 'json'
5
+
6
+ module Ticktok
7
+
8
+ class Clock
9
+
10
+ def initialize(name)
11
+ @name = name
12
+ end
13
+
14
+ def self.named(name)
15
+ Clock.new(name)
16
+ end
17
+
18
+ def on(schedule)
19
+ @schedule = schedule
20
+ self
21
+ end
22
+
23
+ def invoke(action)
24
+ channel = create_clock
25
+ consume(channel, action)
26
+ end
27
+
28
+ def create_clock
29
+ resp = RestClient.post("https://ticktok-io-dev.herokuapp.com/api/v1/clocks?access_token=#{ENV["ACCESS_TOKEN"]}",
30
+ {name: @name, schedule: @schedule}.to_json,
31
+ {content_type: :json})
32
+ raise "Failed to create a clock" unless resp.code == 201
33
+ JSON.parse(resp.body)['channel']
34
+ end
35
+
36
+ def consume(tick_channel, action)
37
+ connection = Bunny.new(tick_channel['details']['uri'])
38
+ connection.start
39
+
40
+ ch = connection.create_channel
41
+
42
+ queue = ch.queue(tick_channel['details']['queue'], :passive => true)
43
+ begin
44
+ queue.subscribe(block: true) do |delivery_info, _properties, body|
45
+ action.call(body)
46
+ end
47
+ rescue Interrupt => _
48
+ ch.close
49
+ connection.close
50
+ end
51
+ end
52
+ end
53
+
54
+ class TickListener
55
+
56
+ end
57
+
58
+ class TicktokCLI < Thor
59
+ desc "clock", "Create and listen to a new clock"
60
+
61
+ def clock(schedule)
62
+ Clock.named("kuku").on('every.5.seconds').invoke(lambda {
63
+ |m| puts "kuku\tevery.5.seconds\t\t#{Time.new.inspect}"}
64
+ )
65
+ end
66
+ end
67
+
68
+ TicktokCLI.start(ARGV)
69
+ end
metadata ADDED
@@ -0,0 +1,42 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ticktok-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eli Segal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/app.rb
20
+ homepage:
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubygems_version: 3.0.1
39
+ signing_key:
40
+ specification_version: 4
41
+ summary: CLI for ticktok.io
42
+ test_files: []