sygnal 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sygnal.rb +42 -0
  2. metadata +45 -0
data/lib/sygnal.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'rubygems'
4
+ require 'json'
5
+
6
+ class SygnalGenerator
7
+
8
+ def initialize(sygnal_type_id, access_token)
9
+ @access_token = access_token
10
+ @sygnal_type_id = sygnal_type_id
11
+ end
12
+
13
+ def access_token
14
+ return @access_token
15
+ end
16
+
17
+ def sygnal_type_id
18
+ return @sygnal_type_id
19
+ end
20
+
21
+ def generate_sygnal(message)
22
+
23
+ uri = URI.parse("http://www.sygnal.io/api/v1/sygnals")
24
+
25
+ post_params = {
26
+ :sygnal_type_id => @sygnal_type_id,
27
+ :message => message
28
+ }
29
+
30
+ request = Net::HTTP::Post.new(uri.path)
31
+ request.body = JSON.generate(post_params)
32
+ request.add_field("Content-Type", "application/json")
33
+ request.add_field("Authorization", "Token token=#{@access_token}")
34
+
35
+ http = Net::HTTP.new(uri.host, uri.port)
36
+ #http.set_debug_output $stdout #useful to see the raw messages going over the wire
37
+
38
+ response = http.request(request)
39
+
40
+ return response
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sygnal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Benjamin R
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Generates sygnals for Sygnal.io prototype.
15
+ email: animalrobot@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/sygnal.rb
21
+ homepage:
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.24
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Generates sygnals for Sygnal.io prototype.
45
+ test_files: []