reflect-rb 0.1.2
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.
- checksums.yaml +7 -0
- data/lib/reflect/client.rb +56 -0
- data/lib/reflect/field.rb +19 -0
- data/lib/reflect/keyspace.rb +54 -0
- data/lib/reflect/version.rb +3 -0
- data/lib/reflect.rb +6 -0
- data/reflect.gemspec +41 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 290a17c71950efb668f30a2919def6ad57028bd4
|
|
4
|
+
data.tar.gz: 2b9c2071b6d970e0ef83db428bc7a0bccb0eef1b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 94a7dfa0f458f8310398a47d591c87165e2c6b2c7b0473ca1c3233c2b0a906d4b8a064a4f53c9ec6bc1ea00f1f9042e1880deae78b13603803564301190257fd
|
|
7
|
+
data.tar.gz: c00044c7eaa763391d740c46714d2ae0f9c9985afeeb8b8110babcbcfa1e4a97d5d91378e3b9079664940bf249767d529da2359992906accb21f8f749f053929
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'httparty'
|
|
3
|
+
require 'reflect/version'
|
|
4
|
+
|
|
5
|
+
module Reflect
|
|
6
|
+
class Client
|
|
7
|
+
include HTTParty
|
|
8
|
+
|
|
9
|
+
base_uri 'https://api.reflect.io'
|
|
10
|
+
|
|
11
|
+
def initialize(token)
|
|
12
|
+
@token = token
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def keyspace(slug)
|
|
16
|
+
res = get("/v1/keyspaces/#{slug}")
|
|
17
|
+
|
|
18
|
+
if res.response.code == "200"
|
|
19
|
+
Keyspace.new(self, JSON.parse(res.body))
|
|
20
|
+
else
|
|
21
|
+
# TODO: What happens if we failed to look this up or whatever?
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get(path)
|
|
27
|
+
self.class.get(path, options)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def post(path, content)
|
|
31
|
+
self.class.post(path, options(body: dump(content)))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def put(path, content)
|
|
35
|
+
self.class.put(path, options(body: dump(content)))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def options(opts={})
|
|
41
|
+
defaults = {
|
|
42
|
+
basic_auth: { username: '', password: @token },
|
|
43
|
+
headers: {
|
|
44
|
+
"User-Agent" => "Reflect Ruby API client v#{Reflect::VERSION}",
|
|
45
|
+
"Content-Type" => "application/json"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
opts.merge(defaults)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def dump(obj)
|
|
53
|
+
JSON.dump(obj)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Reflect
|
|
2
|
+
class Field
|
|
3
|
+
attr_accessor :name
|
|
4
|
+
attr_accessor :column_type
|
|
5
|
+
attr_accessor :type
|
|
6
|
+
attr_accessor :description
|
|
7
|
+
attr_accessor :fields
|
|
8
|
+
attr_accessor :created_at
|
|
9
|
+
attr_accessor :updated_at
|
|
10
|
+
|
|
11
|
+
def initialize(client, attrs={})
|
|
12
|
+
@client = client
|
|
13
|
+
|
|
14
|
+
attrs.each do |k, v|
|
|
15
|
+
self.send("#{k}=".to_s, v)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'time'
|
|
2
|
+
require 'reflect/field'
|
|
3
|
+
|
|
4
|
+
module Reflect
|
|
5
|
+
class Keyspace
|
|
6
|
+
attr_reader :client
|
|
7
|
+
|
|
8
|
+
attr_accessor :name
|
|
9
|
+
attr_accessor :slug
|
|
10
|
+
attr_accessor :statistics_key
|
|
11
|
+
attr_accessor :description
|
|
12
|
+
attr_accessor :fields
|
|
13
|
+
attr_accessor :status
|
|
14
|
+
attr_accessor :created_at
|
|
15
|
+
attr_accessor :updated_at
|
|
16
|
+
|
|
17
|
+
def initialize(client, attrs={})
|
|
18
|
+
@client = client
|
|
19
|
+
|
|
20
|
+
# If we have fields, we'll need to populate them individually.
|
|
21
|
+
fields = attrs.delete("fields")
|
|
22
|
+
|
|
23
|
+
attrs['updated_at'] = Time.parse(attrs['updated_at']) if attrs['updated_at']
|
|
24
|
+
attrs['created_at'] = Time.parse(attrs['created_at']) if attrs['created_at']
|
|
25
|
+
|
|
26
|
+
attrs.each do |k, v|
|
|
27
|
+
self.send("#{k}=".to_s, v)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if fields
|
|
31
|
+
self.fields = fields.map { |f| Field.new(f) }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Appends records to a tablet. If the tablet doesn't exist it will be
|
|
36
|
+
# created.
|
|
37
|
+
#
|
|
38
|
+
# @param String key the key to create
|
|
39
|
+
# @param Array|Hash records the records to create
|
|
40
|
+
#
|
|
41
|
+
def append(key, records)
|
|
42
|
+
client.put("/v1/keyspaces/"+self.slug+"/tablets/"+key, records)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Replaces the existing records in a tablet with a net set of records.
|
|
46
|
+
#
|
|
47
|
+
# @param String key the key to create
|
|
48
|
+
# @param Array|Hash records the records to create
|
|
49
|
+
#
|
|
50
|
+
def replace(key, records)
|
|
51
|
+
client.post("/v1/keyspaces/"+self.slug+"/tablets/"+key, records)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/reflect.rb
ADDED
data/reflect.gemspec
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "reflect/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
FILES = Dir[File.expand_path('../lib/**/*.rb', __FILE__)].map { |fi| fi.gsub(File.expand_path('../', __FILE__) +"/", "") } + ['reflect.gemspec']
|
|
7
|
+
|
|
8
|
+
s.name = "reflect-rb"
|
|
9
|
+
s.version = Reflect::VERSION
|
|
10
|
+
|
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
|
+
s.authors = ["Brad Heller"]
|
|
13
|
+
s.date = "2015-08-30"
|
|
14
|
+
s.description = "Ruby client for Reflect.io"
|
|
15
|
+
s.email = "brad@reflect.io"
|
|
16
|
+
s.files = FILES
|
|
17
|
+
s.homepage = "http://github.com/reflect/reflect-rb"
|
|
18
|
+
s.require_paths = ["lib"]
|
|
19
|
+
s.rubygems_version = "1.8.24"
|
|
20
|
+
s.summary = "Reflect.io API Ruby client"
|
|
21
|
+
|
|
22
|
+
if s.respond_to? :specification_version then
|
|
23
|
+
s.specification_version = 3
|
|
24
|
+
|
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
26
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
|
27
|
+
s.add_development_dependency('rake', '~> 10.1.0')
|
|
28
|
+
s.add_development_dependency('minitest', '~> 5.3')
|
|
29
|
+
else
|
|
30
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
|
31
|
+
s.add_development_dependency('rake', '~> 10.1.0')
|
|
32
|
+
s.add_development_dependency('minitest', '~> 5.3')
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
|
36
|
+
s.add_development_dependency('rake', '~> 10.1.0')
|
|
37
|
+
s.add_development_dependency('minitest', '~> 5.3')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: reflect-rb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brad Heller
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-08-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 10.1.0
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 10.1.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.3'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.3'
|
|
55
|
+
description: Ruby client for Reflect.io
|
|
56
|
+
email: brad@reflect.io
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- lib/reflect.rb
|
|
62
|
+
- lib/reflect/client.rb
|
|
63
|
+
- lib/reflect/field.rb
|
|
64
|
+
- lib/reflect/keyspace.rb
|
|
65
|
+
- lib/reflect/version.rb
|
|
66
|
+
- reflect.gemspec
|
|
67
|
+
homepage: http://github.com/reflect/reflect-rb
|
|
68
|
+
licenses: []
|
|
69
|
+
metadata: {}
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubyforge_project:
|
|
86
|
+
rubygems_version: 2.4.8
|
|
87
|
+
signing_key:
|
|
88
|
+
specification_version: 3
|
|
89
|
+
summary: Reflect.io API Ruby client
|
|
90
|
+
test_files: []
|