brawne 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ require 'net/http'
2
+ require "net/https"
3
+
4
+ #
5
+ # simple module to wrap up http requests.
6
+ module Brawne
7
+ module Request
8
+
9
+ # simple get method
10
+ # call a simple get on host using request
11
+ def self.get(request)
12
+ http_r = Net::HTTP.new(Brawne.host, Brawne.port)
13
+ http_r.use_ssl = Brawne.ssl
14
+ response = nil
15
+ begin
16
+ http_r.start() do |http|
17
+ req = Net::HTTP::Get.new(request)
18
+ req.add_field("USERNAME", Brawne.user)
19
+ req.add_field("TOKEN", Brawne.token)
20
+ response = http.request(req)
21
+ end
22
+ return [response.code, response.body]
23
+ rescue Errno::ECONNREFUSED
24
+ return [503, "unavailable"]
25
+ end
26
+ end
27
+
28
+ # simple post method.
29
+ # send the payload to the host with request
30
+ # the payload is expected to be json
31
+ def self.post(request,payload)
32
+ http_r = Net::HTTP.new(Brawne.host, Brawne.port)
33
+ http_r.use_ssl = Brawne.ssl
34
+ response = nil
35
+ begin
36
+ http_r.start() do |http|
37
+ req = Net::HTTP::Post.new(request, initheader = {'Content-Type' =>'application/json'})
38
+ req.add_field("USERNAME", Brawne.user)
39
+ req.add_field("TOKEN", Brawne.token)
40
+ req.body = payload
41
+ req.set_form_data(payload)
42
+ response = http.request(req)
43
+ end
44
+ return [response.code, response.body]
45
+ rescue Errno::ECONNREFUSED
46
+ return [503, "unavailable"]
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Brawne
2
+ VERSION = '0.0.6'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brawne
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-16 00:00:00.000000000 +02:00
13
+ date: 2011-09-17 00:00:00.000000000 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
  description: Make request thrown Net::Http
@@ -20,6 +20,8 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - lib/brawne.rb
23
+ - lib/brawne/version.rb
24
+ - lib/brawne/request.rb
23
25
  has_rdoc: true
24
26
  homepage: http://joelazemar.fr
25
27
  licenses: []