codecore_jukebox 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
+ SHA1:
3
+ metadata.gz: f4d29e986d27d219581bc667521a5f2e3b52a0bb
4
+ data.tar.gz: dd2390097cd20eeef2aaecec574dc7ba4d730aab
5
+ SHA512:
6
+ metadata.gz: d80bcfcbd18a28c35068541ef750d4bab438f89a5fa28d0b2cf660681351edb811421bc649314baa262c37c2a05da98335fd7e9ee8f17fb88539057bfbba4189
7
+ data.tar.gz: 50cd01b34b64321c16d814b5741c8829aa8d11d2b2e375d81ff1740840b8654c177eb33ea7654f917883c87d39c3c4a073ef99a4581f8fe94ec348acc29fe2e9
@@ -0,0 +1,10 @@
1
+ require "cowsay"
2
+
3
+
4
+ class CodecoreJukebox
5
+ def self.send(name, notes, bpm = nil)
6
+ Connector.new.send(name, notes, bpm)
7
+ end
8
+ end
9
+
10
+ require 'codecore_jukebox/connector'
@@ -0,0 +1,45 @@
1
+ require "faraday"
2
+ require "json"
3
+ require "cowsay"
4
+
5
+ class CodecoreJukebox::Connector
6
+ DEFAULT_URL = "https://codecore-jukebox.herokuapp.com/"
7
+
8
+ def initialize(url = DEFAULT_URL)
9
+ @url = url
10
+ end
11
+
12
+ def send(name, notes, bpm=nil)
13
+ unless notes.is_a? Array
14
+ puts Cowsay.say("Oooops! The second argument must be an Array of Hashes!")
15
+ return
16
+ end
17
+ notes_json = JSON.generate(notes)
18
+ response = conn.post '/songs', {name: name,
19
+ notes_json: notes_json,
20
+ bpm: bpm}
21
+ print_response(response.status)
22
+ end
23
+
24
+ private
25
+
26
+ def conn
27
+ @conn ||= Faraday.new(:url => @url) do |faraday|
28
+ faraday.request :url_encoded # form-encode POST params
29
+ faraday.response :logger # log requests to STDOUT
30
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
31
+ end
32
+ end
33
+
34
+ def print_response(status)
35
+ if status == 201
36
+ puts Cowsay.say("Song Successfully uploaded, check it on #{@url}")
37
+ else
38
+ puts Cowsay.say("Sorry Something went wrong :(")
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ # c = Connector.new("http://localhost:3000")
45
+ # c.send("test1", [{pitch: 'A', beats: 1}, {pitch: 'B#', beats: 2}], 200)
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codecore_jukebox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tam Kbeili
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Gem to connect to CodeCore Jukebox test site
14
+ email: tam@codecore.ca
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/codecore_jukebox.rb
20
+ - lib/codecore_jukebox/connector.rb
21
+ homepage: http://rubygems.org/gems/codecore_jukebox
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.7
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Connect to CodeCore's Jukebox test site
45
+ test_files: []