pavlok 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 990f70453b5d3a6a8d3c295c78f4d2eb53a2c81225e7b3b43d2777077c4382ec
4
+ data.tar.gz: fae8f39d9913b5aa850dfb60bc78cb6662438861ad200c4c84b8d3bd042b25c0
5
+ SHA512:
6
+ metadata.gz: 2f68d36f36fcab0b336498e0f9ebbf37bff095c6a62c514fc05d83bc89495e5b0a9b6832f41220f85b442523017448d03bba9c9d92e8e36a30c88bd95aa24124
7
+ data.tar.gz: 8de77468da8f6c32182f346ef93c5f6a01170e741093369c030d0b589063a1c4027e8026f458196ea09949f05f5c6f0ea271d127219c72cedec865eecc174ec9
@@ -0,0 +1,38 @@
1
+ require 'pavlok/stimulus'
2
+ require 'pavlok/web'
3
+
4
+ class Pavlok
5
+ attr_reader :token
6
+
7
+ def initialize(token)
8
+ @token = token
9
+ end
10
+
11
+ def zap(intensity:, message:)
12
+ Pavlok::Web.send(build_stimulus("zap", intensity, message))
13
+ end
14
+
15
+ def beep(intensity:, message:)
16
+ Pavlok::Web.send(build_stimulus("zap", intensity, message))
17
+ end
18
+
19
+ def vibration(intensity:, message:)
20
+ Pavlok::Web.send(build_stimulus("zap", intensity, message))
21
+ end
22
+
23
+ def user_info
24
+ "not yet implemented"
25
+ end
26
+
27
+ def possibilities
28
+ puts [
29
+ "#zap -> send zap to user",
30
+ "#beep -> send beep to user",
31
+ "#vibration -> send vibration to user",
32
+ "#user_info -> fetches information about the user"
33
+ ]
34
+ end
35
+ def build_stimulus(kind, intensity, message)
36
+ Pavlok::Stimulus.send("make_#{kind}".to_sym, *[intensity, zap])
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ module Pavlok
2
+ class InvalidStimulusValueError < StandardError
3
+ def message
4
+ "Value must remain within 1-100 range"
5
+ end
6
+ end
7
+
8
+ class InvalidStimulusTypeError < StandardError
9
+ def message
10
+ "Kind must be either zap, beep or vibrate"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ module Pavlok
2
+ class Stimulus
3
+ attr_reader :stimulus, @errors
4
+
5
+ VALID_RANGES = {
6
+ "zap": 1..100,
7
+ "vibration": 1..100,
8
+ "beep": 1..100,
9
+ }
10
+
11
+ def initialize(kind, value, message)
12
+ validate
13
+ @kind, @value, @message = kind, value, message
14
+ @stimulus = OpenStruct.new(value: value, kind: kind, message: message, data: { reason: message })
15
+ end
16
+
17
+ def self.make_zap(intensity:, message:)
18
+ self.new("zap", transform_to_api(intensity), message)
19
+ end
20
+
21
+ def self.make_vibrate(intensity:, message:)
22
+ self.new("vibration", transform_to_api(intensity), message)
23
+ end
24
+
25
+ def self.make_beep(tune:, message:)
26
+ self.new("beep", transform_to_api(tune), message)
27
+ end
28
+
29
+ private
30
+
31
+ def validate
32
+ raise InvalidStimulusTypeError if !VALID_RANGES.keys.include?(@kind)
33
+ raise InvalidStimulusValueError if !VALID_RANGES[@kind].include?(@value)
34
+ end
35
+
36
+ def transform_to_api(value)
37
+ ((value.to_f / 255) * 100).ceil.to_i
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,57 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Pavlok
6
+ class Web
7
+ HOST = "https://app.pavlok.com"
8
+ API_PATH = "api/v1"
9
+
10
+ def self.call(stimulus, token)
11
+ attempt = self.new(stimulus, token)
12
+ attempt.call
13
+ end
14
+
15
+ def initialize(stimulus, token)
16
+ @stimulus, @token = stimulus, token
17
+ end
18
+
19
+ def call
20
+ response = post
21
+ end
22
+
23
+ def post
24
+ puts url
25
+ client.post(url, data, headers)
26
+ end
27
+
28
+ def client
29
+ @client = Net::HTTP
30
+ end
31
+
32
+ def url
33
+ URI([host, path].join("/"))
34
+ end
35
+
36
+ def host
37
+ HOST
38
+ end
39
+
40
+ def path
41
+ [API_PATH, @stimulus.kind, @stimulus.value].join("/")
42
+ end
43
+
44
+ def data
45
+ @stimulus.data.to_json
46
+ end
47
+
48
+ def headers
49
+ {
50
+ "Content-Type" => "application/json",
51
+ "Authorization" => "Bearer #{@token}"
52
+ }
53
+ end
54
+
55
+
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pavlok
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Pavlok
8
+ - Igor Britto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-08-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Send vibrations, beeps and zaps to user's pavloks
15
+ email: ops@pavlok.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/pavlok.rb
21
+ - lib/pavlok/errors.rb
22
+ - lib/pavlok/stimulus.rb
23
+ - lib/pavlok/web.rb
24
+ homepage: https://rubygems.org/gems/pavlok
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.8
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Pavlok integration for stimuli!
48
+ test_files: []