brawne 0.0.1 → 0.0.2

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/brawne.rb +23 -24
  2. metadata +21 -38
data/lib/brawne.rb CHANGED
@@ -1,28 +1,27 @@
1
- require 'net/http'
2
- require "net/https"
1
+ require 'active_support/core_ext/module/attribute_accessors'
3
2
 
4
- class Brawne
5
-
6
- attr_accessor :host, :port, :ssl, :user, :token
7
-
8
- def initialize(host, port, ssl, user, token)
9
- @host, @port, @ssl, @user, @token = host, port, ssl, user, token
3
+ module Brawne
4
+ @@_ran_once = false
5
+
6
+ mattr_accessor :host, :port, :ssl, :user, :token
7
+ @@host, @@port, @@ssl, @@user, @@token = nil, nil, nil, nil, nil
8
+
9
+ def self.setup
10
+ yield self if @@_ran_once == false
11
+ @@_ran_once = true
12
+ end
13
+
14
+ def self.load_and_set_settings!
15
+ Kernel.send(:remove_const, 'BRAWNE_HOST') if Kernel.const_defined?('BRAWNE_HOST')
16
+ Kernel.const_set('BRAWNE_HOST', Brawne.host)
17
+ Kernel.send(:remove_const, 'BRAWNE_PORT') if Kernel.const_defined?('BRAWNE_PORT')
18
+ Kernel.const_set('BRAWNE_PORT', Brawne.port)
19
+ Kernel.send(:remove_const, 'BRAWNE_SSL') if Kernel.const_defined?('BRAWNE_SSL')
20
+ Kernel.const_set('BRAWNE_SSL', Brawne.ssl)
21
+ Kernel.send(:remove_const, 'BRAWNE_USER') if Kernel.const_defined?('BRAWNE_USER')
22
+ Kernel.const_set('BRAWNE_USER', Brawne.user)
23
+ Kernel.send(:remove_const, 'BRAWNE_TOKEN') if Kernel.const_defined?('BRAWNE_TOKEN')
24
+ Kernel.const_set('BRAWNE_TOKEN', Brawne.token)
10
25
  end
11
26
 
12
- def get(request)
13
- http_r = Net::HTTP.new(@host, @port)
14
- http_r.use_ssl = @ssl
15
- response = nil
16
- begin
17
- http_r.start() do |http|
18
- req = Net::HTTP::Get.new(request)
19
- req.add_field("USERNAME", @user)
20
- req.add_field("TOKEN", @token)
21
- response = http.request(req)
22
- end
23
- return [response.code, response.body]
24
- rescue Errno::ECONNREFUSED
25
- return [503, "unavailable"]
26
- end
27
-
28
27
  end
metadata CHANGED
@@ -1,62 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: brawne
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Joel AZEMAR
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-09-15 00:00:00 +02:00
18
- default_executable:
12
+ date: 2011-09-15 00:00:00.000000000Z
19
13
  dependencies: []
20
-
21
14
  description: Make request thrown Net::Http
22
15
  email: joel.azemar@gmail.com
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
18
  extra_rdoc_files: []
28
-
29
- files:
19
+ files:
30
20
  - lib/brawne.rb
31
- has_rdoc: true
32
21
  homepage: http://joelazemar.fr
33
22
  licenses: []
34
-
35
23
  post_install_message:
36
24
  rdoc_options: []
37
-
38
- require_paths:
25
+ require_paths:
39
26
  - lib
40
- required_ruby_version: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 0
46
- version: "0"
47
- required_rubygems_version: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- segments:
52
- - 0
53
- version: "0"
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'
54
39
  requirements: []
55
-
56
40
  rubyforge_project:
57
- rubygems_version: 1.3.6
41
+ rubygems_version: 1.8.10
58
42
  signing_key:
59
43
  specification_version: 3
60
44
  summary: Brawne!
61
45
  test_files: []
62
-