graphenedb 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 807d28aea20369b663681983670787e8b324a427
4
+ data.tar.gz: 186c99ec28b2fb1085cc2d01dcf55cd1380dc57b
5
+ SHA512:
6
+ metadata.gz: cb8ac16c7a662e38f66ba6fadc61bc4413d7d9e1e6f6a46fc95b8bef9a7610e18e86054a689f9f5a98e7a7d9de5b29e8fd3c1c0a89230efa7268094aa079d43f
7
+ data.tar.gz: d2a2124aa56ca60c5ca6676b57530e1918fea69e1dd2290b04345a35c47bac284cd8ada128e41d73d5342f32d960a71c79b9d26a61f41e2ad7f508c82facc035
@@ -0,0 +1,164 @@
1
+ require "net/https"
2
+ require "uri"
3
+ require "json"
4
+
5
+ ENDPOINT = "https://api.graphenedb.com/v1"
6
+
7
+ # Where http calls are made
8
+ require_relative "requests"
9
+ require_relative 'graphenedb/configuration'
10
+
11
+ module Graphenedb
12
+ # graphenedb configuration
13
+ class << self
14
+ attr_accessor :configuration
15
+ end
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+ def self.reset
20
+ @configuration = Configuration.new
21
+ end
22
+ def self.configure
23
+ yield(configuration)
24
+ end
25
+
26
+ # --------------------------------------
27
+
28
+ # List all databases
29
+ def self.databases
30
+ get('databases')
31
+ end
32
+ # Get one database
33
+ def self.database(id)
34
+ get("databases/#{id}")
35
+ end
36
+ # Empty a database
37
+ def self.empty_database(id)
38
+ put("databases/#{id}/empty")
39
+ end
40
+ # Export a database
41
+ def self.export_database(id)
42
+ put("databases/#{id}/export")
43
+ end
44
+ # restart database
45
+ def self.restart_database(id)
46
+ put("databases/#{id}/restart")
47
+ end
48
+ # create database
49
+ def self.create_database(val, opts = {})
50
+ if val.is_a?(String)
51
+ name = val
52
+ val = {}
53
+ end
54
+ body = {
55
+ name: val[:name] || name,
56
+ version: val[:version] || Graphenedb.configuration.version,
57
+ awsRegion: val[:region] || Graphenedb.configuration.region,
58
+ plan: val[:plan] || Graphenedb.configuration.plan
59
+ }
60
+ post("databases", body)
61
+ end
62
+ # clone database
63
+ def self.clone_database(val, name = nil, opts = {})
64
+ if val.is_a?(String)
65
+ id = val
66
+ val = {}
67
+ else
68
+ id = val[:id]
69
+ end
70
+ body = {
71
+ name: val[:name] || name,
72
+ version: val[:version] || Graphenedb.configuration.version,
73
+ awsRegion: val[:region] || Graphenedb.configuration.region,
74
+ plan: val[:plan] || Graphenedb.configuration.plan
75
+ }
76
+ post("databases/#{id}/clone", body)
77
+ end
78
+ # delete database
79
+ def self.delete_database(id)
80
+ delete("databases/#{id}")
81
+ end
82
+
83
+ # -------------------------------------------------
84
+
85
+ # Get database users
86
+ def self.users(id)
87
+ get("databases/#{id}/users")
88
+ end
89
+ # Get database user
90
+ def self.user(did, uid)
91
+ get("databases/#{did}/users/#{uid}")
92
+ end
93
+ # create database user
94
+ def self.create_user(val, desc = nil, opts = {})
95
+ if val.is_a?(String)
96
+ id = val
97
+ val = {}
98
+ else
99
+ id = opts[:database]
100
+ end
101
+ body = {
102
+ description: opts[:description] || desc,
103
+ expireAt: opts[:expire_at] || 'never'
104
+ }
105
+ post("databases/#{id}/users", body)
106
+ end
107
+ # Get database user
108
+ def self.delete_user(did, uid)
109
+ delete("databases/#{did}/users/#{uid}")
110
+ end
111
+
112
+ # ---------------------------------------------
113
+
114
+ # List database backups
115
+ def self.backups(id)
116
+ get("databases/#{id}/backups")
117
+ end
118
+ # Get one database backup
119
+ def self.backup(did, bid)
120
+ get("databases/#{did}/backups/#{bid}")
121
+ end
122
+ # Get database backup url
123
+ def self.backup_url(did, bid)
124
+ get("databases/#{did}/backups/#{bid}/package")
125
+ end
126
+ # Get backup schedules
127
+ def self.all_backup_schedules(id)
128
+ get("databases/#{id}/backups/schedule")
129
+ end
130
+ # Get backup schedules
131
+ def self.backup_schedules(opts = {})
132
+ put("databases/#{opts[:id]}/backups/schedule", opts)
133
+ end
134
+ # Manual backup of database
135
+ def self.snapshot(id)
136
+ put("databases/#{id}/snapshot")
137
+ end
138
+ # Restore backup to database
139
+ def self.restore_backup(did, bid)
140
+ put("databases/#{did}/backups/#{bid}/restore")
141
+ end
142
+ # Import backup to database
143
+ def self.import(val, url = nil, opts = {})
144
+ if val.is_a?(String)
145
+ id = val
146
+ val = {}
147
+ else
148
+ id = val[:id]
149
+ end
150
+ body = { url: val[:url] || url }
151
+ put("databases/#{id}/snapshot", body)
152
+ end
153
+
154
+ # ------------------------------------------------
155
+
156
+ # List available database versions
157
+ def self.versions
158
+ get("databases/versions")
159
+ end
160
+ # Get the status of an async operation
161
+ def self.operation(id)
162
+ get("operations/#{id}")
163
+ end
164
+ end
@@ -0,0 +1,12 @@
1
+ module Graphenedb
2
+ class Configuration
3
+ attr_accessor :api_key, :version, :region, :plan
4
+
5
+ def initialize
6
+ @api_key = nil
7
+ @version = 'v314'
8
+ @region = 'us-east-1'
9
+ @plan = 'sandbox'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ ## HTTP Request Methods
2
+ def get(*args)
3
+ call(args.insert(0, 'Get'))
4
+ end
5
+
6
+ def post(*args)
7
+ call(args.insert(0, 'Post'))
8
+ end
9
+
10
+ def put(*args)
11
+ call(args.insert(0, 'Put'))
12
+ end
13
+
14
+ def delete(*args)
15
+ call(args.insert(0, 'Delete'))
16
+ end
17
+
18
+ ## API call method
19
+ def call(args)
20
+ method = args[0]
21
+ path = args[1]
22
+ params = args[2]
23
+
24
+ # arguments = args.flatten
25
+ # construct api endpoint
26
+ uri = URI("#{ENDPOINT}/#{path}")
27
+ http = Net::HTTP.new(uri.host, uri.port)
28
+
29
+ # use ssl
30
+ http.use_ssl = true
31
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
+
33
+ # construct request
34
+ req = Net::HTTP.const_get(method).new(uri.request_uri)
35
+ req['api_key'] = Graphenedb.configuration.api_key
36
+ req['Accept'] = 'text/html'
37
+ req['Content-Type'] = 'application/json'
38
+ req.body = params.to_json
39
+
40
+ # parse response
41
+ res = http.request(req)
42
+
43
+ if res.code == '401'
44
+ "Unauthorized. Have you configured your GrapheneDB api key?"
45
+ else
46
+ JSON.parse(res.body)
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphenedb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ricky Brown
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple & Slim Ruby SDK for the GrapheneDB API
14
+ email: ricky@brilliantlabs.co
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/graphenedb.rb
20
+ - lib/graphenedb/configuration.rb
21
+ - lib/requests.rb
22
+ homepage: https://github.com/rickybrown/graphenedb
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.6.11
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: GrapheneDB for Ruby
46
+ test_files: []