lacuna 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lacuna.rb +23 -100
- data/lib/lacuna/constants.rb +12 -0
- data/lib/lacuna/extras/body.rb +9 -0
- data/lib/lacuna/extras/empire.rb +9 -0
- data/lib/lacuna/module.rb +66 -0
- data/lib/lacuna/session.rb +22 -0
- data/lib/lacuna/version.rb +5 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfcb24ca00be1e677b7416e35e97a471c8d9977b
|
4
|
+
data.tar.gz: 0dc4970c21acbdfa6de03a368d4756f96a93142c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5aba662d10e3ffb5589193e55445c927901fd23504914df8a5578142a184e6a6af393c3fe06110ee5feb984ecc3fe7de36dd404ab316f2fcf5a354c7e983635
|
7
|
+
data.tar.gz: 74986f5ff81314826c9e94336d1d0e52098317bb9821b4455495f36a16c37e8449c3b0f1bf4981d8938dab4a680de3d0f3f09942ee11d3f701285bb2c6e53a10
|
data/lib/lacuna.rb
CHANGED
@@ -1,134 +1,57 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
|
4
|
+
$LOAD_PATH.unshift File.dirname __FILE__
|
5
|
+
|
4
6
|
require 'net/http'
|
5
7
|
require 'openssl'
|
6
8
|
require 'json'
|
9
|
+
require 'require_all'
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@@session = val
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.end
|
16
|
-
self.set nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.get
|
20
|
-
@@session
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.valid?
|
24
|
-
# TODO: take into account the two hour session timeout.
|
25
|
-
!@@session.nil?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class Lacuna
|
30
|
-
VERSION = '0.0.2'
|
11
|
+
require 'lacuna/version'
|
12
|
+
require 'lacuna/session'
|
13
|
+
require 'lacuna/constants'
|
14
|
+
require 'lacuna/module'
|
31
15
|
|
32
|
-
|
33
|
-
# Private key : 66090c68-2d51-47fa-b406-44dc98e6f6d3
|
34
|
-
'us1' => 'bbd9b648-6e45-419d-bdaf-5726919c4a64',
|
35
|
-
# Private key : 3a9c5121-0939-4ef9-82c2-7c1aa4f7d1bc
|
36
|
-
'pt' => '3746d4a2-0f44-44db-9308-22a85c234aab',
|
37
|
-
}
|
16
|
+
require_all File.join(File.dirname(__FILE__), 'lacuna', 'extras')
|
38
17
|
|
39
|
-
|
18
|
+
module Lacuna
|
40
19
|
|
41
|
-
def
|
20
|
+
def self.connect(args)
|
42
21
|
# Allow a custom server url, be specifying the API key used there but
|
43
22
|
# allow the name of the server (eg: 'us1') to be used, which selects
|
44
23
|
# the API key corresponding to US1.
|
45
|
-
|
24
|
+
@@api_key =
|
46
25
|
if args[:api_key]
|
47
26
|
args[:api_key]
|
48
27
|
elsif args[:server_name] && !args[:server_url]
|
49
28
|
API_KEYS[args[:server_name]]
|
50
29
|
end
|
51
30
|
|
52
|
-
|
31
|
+
@@url =
|
53
32
|
if args[:server_url]
|
54
33
|
args[:server_url]
|
55
34
|
elsif args[:server_name]
|
56
35
|
File.join('https://', args[:server_name] + '.' + LACUNA_DOMAIN)
|
57
36
|
end
|
58
37
|
|
59
|
-
|
38
|
+
@@args = args
|
60
39
|
|
61
40
|
# TODO: allow a sleep-period for each request
|
62
41
|
end
|
63
42
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class LacunaModule
|
71
|
-
|
72
|
-
def initialize(base_url, module_name, args)
|
73
|
-
@base_url = base_url
|
74
|
-
@url = base_url
|
75
|
-
@module_name = module_name
|
76
|
-
@method_name = 'replace me!'
|
77
|
-
@args = args
|
78
|
-
end
|
79
|
-
|
80
|
-
def send(url, post_module, post_method, data)
|
81
|
-
uri = URI.parse url
|
82
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
83
|
-
http.use_ssl = true
|
84
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
85
|
-
|
86
|
-
request = Net::HTTP::Post.new '/' + post_module
|
87
|
-
request.add_field('Content-Type', 'application/json')
|
88
|
-
|
89
|
-
body = {
|
90
|
-
:id => 1,
|
91
|
-
:jsonrpc => '2.0',
|
92
|
-
:method => post_method,
|
93
|
-
:params => data
|
94
|
-
}
|
95
|
-
|
96
|
-
# Include session id in requests that need it
|
97
|
-
if "#{post_module}/#{post_method}" != 'empire/login'
|
98
|
-
body[:params].unshift Session.get
|
99
|
-
end
|
100
|
-
|
101
|
-
request.body = JSON.generate body
|
102
|
-
|
103
|
-
response = http.request request
|
104
|
-
rv = JSON.parse response.read_body
|
105
|
-
|
106
|
-
# TODO: if !rv['error'].nil? throw an exception
|
107
|
-
if rv['result']
|
108
|
-
rv['result']
|
109
|
-
else
|
110
|
-
rv
|
111
|
-
end
|
112
|
-
end
|
43
|
+
@@url = ''
|
44
|
+
@@args = {}
|
45
|
+
@@api_key = ''
|
46
|
+
def self.url; @@url; end
|
47
|
+
def self.args; @@args; end
|
48
|
+
def self.api_key; @@api_key; end
|
113
49
|
|
114
|
-
|
115
|
-
|
116
|
-
if !Session.valid?
|
117
|
-
res = self.send(@base_url, 'empire', 'login', [
|
118
|
-
@args[:name],
|
119
|
-
@args[:password],
|
120
|
-
@args[:api_key],
|
121
|
-
])
|
122
|
-
Session.set res['session_id']
|
123
|
-
else
|
124
|
-
# check time
|
125
|
-
return
|
126
|
-
end
|
50
|
+
class Empire < Lacuna::Extras::Empire
|
51
|
+
@module_name = 'empire'
|
127
52
|
end
|
128
53
|
|
129
|
-
|
130
|
-
@
|
131
|
-
self.session_stuff
|
132
|
-
self.send(@url, @module_name, @method_name, args)
|
54
|
+
class Body < Lacuna::Extras::Body
|
55
|
+
@module_name = 'body'
|
133
56
|
end
|
134
57
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Lacuna
|
4
|
+
API_KEYS = {
|
5
|
+
# Private key : 66090c68-2d51-47fa-b406-44dc98e6f6d3
|
6
|
+
'us1' => 'bbd9b648-6e45-419d-bdaf-5726919c4a64',
|
7
|
+
# Private key : 3a9c5121-0939-4ef9-82c2-7c1aa4f7d1bc
|
8
|
+
'pt' => '3746d4a2-0f44-44db-9308-22a85c234aab',
|
9
|
+
}
|
10
|
+
|
11
|
+
LACUNA_DOMAIN = 'lacunaexpanse.com'
|
12
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Lacuna
|
4
|
+
class Module
|
5
|
+
def self.send(url, post_module, post_method, data)
|
6
|
+
uri = URI.parse url
|
7
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
8
|
+
http.use_ssl = true
|
9
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
10
|
+
|
11
|
+
request = Net::HTTP::Post.new '/' + post_module
|
12
|
+
request.add_field('Content-Type', 'application/json')
|
13
|
+
|
14
|
+
body = {
|
15
|
+
:id => 1,
|
16
|
+
:jsonrpc => '2.0',
|
17
|
+
:method => post_method,
|
18
|
+
:params => data
|
19
|
+
}
|
20
|
+
|
21
|
+
# Include session id in requests that need it
|
22
|
+
if "#{post_module}/#{post_method}" != 'empire/login'
|
23
|
+
body[:params].unshift Session.get
|
24
|
+
end
|
25
|
+
|
26
|
+
request.body = JSON.generate body
|
27
|
+
|
28
|
+
response = http.request request
|
29
|
+
rv = JSON.parse response.read_body
|
30
|
+
|
31
|
+
if rv['result']
|
32
|
+
rv['result']
|
33
|
+
elsif rv['error']
|
34
|
+
# TODO: throw error?
|
35
|
+
p rv['error']
|
36
|
+
rv['error']
|
37
|
+
else
|
38
|
+
rv
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Check that we're logged in, if not, get session a set up.
|
43
|
+
def self.session_stuff
|
44
|
+
if !Session.valid?
|
45
|
+
res = self.send(Lacuna.url, 'empire', 'login', [
|
46
|
+
Lacuna.args[:name],
|
47
|
+
Lacuna.args[:password],
|
48
|
+
Lacuna.api_key,
|
49
|
+
])
|
50
|
+
Session.set res['session_id']
|
51
|
+
else
|
52
|
+
# check time
|
53
|
+
return
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.method_missing(name, *args)
|
58
|
+
if !@module_name.nil?
|
59
|
+
self.session_stuff
|
60
|
+
self.send(Lacuna.url, @module_name, name.id2name, args)
|
61
|
+
else
|
62
|
+
puts "#{self} isn't working!"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Session
|
4
|
+
@@session = nil
|
5
|
+
|
6
|
+
def self.set(val)
|
7
|
+
@@session = val
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.end
|
11
|
+
self.set nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get
|
15
|
+
@@session
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.valid?
|
19
|
+
# TODO: take into account the two hour session timeout.
|
20
|
+
!@@session.nil?
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lacuna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan McCallum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2010-
|
11
|
+
date: 2010-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Lacuna is a Ruby library for using the API of The Lacuna Expanse.
|
14
14
|
email: nmccallum7@gmail.com
|
@@ -17,6 +17,12 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/lacuna.rb
|
20
|
+
- lib/lacuna/constants.rb
|
21
|
+
- lib/lacuna/extras/body.rb
|
22
|
+
- lib/lacuna/extras/empire.rb
|
23
|
+
- lib/lacuna/module.rb
|
24
|
+
- lib/lacuna/session.rb
|
25
|
+
- lib/lacuna/version.rb
|
20
26
|
homepage: http://rubygems.org/gems/lacuna
|
21
27
|
licenses:
|
22
28
|
- MIT
|