lacuna 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/lacuna.rb +109 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e03e847bc99ee187e2123d35c96c6c5250667522
4
+ data.tar.gz: 7fbd7e23672ff56eb2a82e8604479303be7f7bdb
5
+ SHA512:
6
+ metadata.gz: ea0d01b6e175948009a737a1eed5953f73395c898bdfe39332b0c73b5d0cd518184f9d493b3d520f554d960bc309be21aaac16af2107f14e725d0edf8aabf790
7
+ data.tar.gz: 3f8c2ad1e55cd59fe37ab9dd85c9770a1434ed1c3667c2f2a91c8c3faa31c1c43503a1aada5dc311cd6298d7c3f76afe51293411be1a7334a88c7bfc243980ca
data/lib/lacuna.rb ADDED
@@ -0,0 +1,109 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'net/http'
5
+ require 'openssl'
6
+ require 'json'
7
+
8
+ class Lacuna
9
+ VERSION = '0.0.1'
10
+
11
+ API_KEYS = {
12
+ # Private key : 66090c68-2d51-47fa-b406-44dc98e6f6d3
13
+ 'us1' => 'bbd9b648-6e45-419d-bdaf-5726919c4a64',
14
+ }
15
+
16
+ LACUNA_DOMAIN = 'lacunaexpanse.com'
17
+
18
+ def initialize(args)
19
+ # Allow a custom server url, be specifying the API key used there but
20
+ # allow the name of the server (eg: 'us1') to be used, which selects
21
+ # the API key corresponding to US1.
22
+ @api_key =
23
+ if args[:api_key]
24
+ args[:api_key]
25
+ elsif args[:server_name] && !args[:server_url]
26
+ API_KEYS[args[:server_name]]
27
+ end
28
+
29
+ @url =
30
+ if args[:server_url]
31
+ args[:server_url]
32
+ elsif args[:server_name]
33
+ File.join('https://', args[:server_name] + '.' + LACUNA_DOMAIN)
34
+ end
35
+
36
+ @args = args
37
+
38
+ # TODO: allow a sleep-period for each request
39
+ end
40
+
41
+ def method_missing(name, *args)
42
+ args = @args.merge :api_key => @api_key
43
+ LacunaModule.new(@url, name.id2name, args)
44
+ end
45
+ end
46
+
47
+ class LacunaModule
48
+
49
+ def initialize(base_url, module_name, args)
50
+ @base_url = base_url
51
+ @url = base_url
52
+ @module_name = module_name
53
+ @method_name = 'replace me!'
54
+ @args = args
55
+ end
56
+
57
+ def send(url, post_module, post_method, data)
58
+ uri = URI.parse url
59
+ http = Net::HTTP.new(uri.host, uri.port)
60
+ http.use_ssl = true
61
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
62
+
63
+ request = Net::HTTP::Post.new '/' + post_module
64
+ request.add_field('Content-Type', 'application/json')
65
+
66
+ body = {
67
+ :id => 1,
68
+ :jsonrpc => '2.0',
69
+ :method => post_method,
70
+ :params => data
71
+ }
72
+ if "#{post_module}/#{post_method}" != 'empire/login'
73
+ body[:params].unshift @session_id
74
+ end
75
+
76
+ request.body = JSON.generate body
77
+
78
+ response = http.request request
79
+ rv = JSON.parse response.read_body
80
+
81
+ # TODO: if !rv['error'].nil? throw an exception
82
+ if rv['result']
83
+ rv['result']
84
+ else
85
+ rv
86
+ end
87
+ end
88
+
89
+ # Check that we're logged in, if not, get session a set up.
90
+ def session_stuff
91
+ if !@session_id
92
+ res = self.send(@base_url, 'empire', 'login', [
93
+ @args[:name],
94
+ @args[:password],
95
+ @args[:api_key],
96
+ ])
97
+ @session_id = res['session_id']
98
+ else
99
+ # check time
100
+ return
101
+ end
102
+ end
103
+
104
+ def method_missing(name, *args)
105
+ @method_name = name.id2name
106
+ self.session_stuff
107
+ self.send(@url, @module_name, @method_name, args)
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lacuna
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan McCallum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-05-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Lacuna is a Ruby library for using the API of The Lacuna Expanse.
14
+ email: nmccallum7@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/lacuna.rb
20
+ homepage: http://rubygems.org/gems/lacuna
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Lacuna is a Ruby library for using the API of The Lacuna Expanse.
44
+ test_files: []