simperuby 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.
- data/lib/simperuby.rb +75 -0
- metadata +58 -0
data/lib/simperuby.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Simperuby
|
5
|
+
attr_accessor :access_token
|
6
|
+
|
7
|
+
def initialize(params={})
|
8
|
+
if params[:app_id]
|
9
|
+
@app_id = params[:app_id]
|
10
|
+
else
|
11
|
+
raise 'You need to provide an :app_id'
|
12
|
+
end
|
13
|
+
if params[:api_key]
|
14
|
+
@api_key = params[:api_key]
|
15
|
+
else
|
16
|
+
raise 'You need to provide an :api_key'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(user,pass)
|
21
|
+
res = JSON.parse RestClient.post "https://auth.simperium.com/1/#{@app_id}/create/", { 'username' => user, 'password' => pass }.to_json, { 'X-Simperium-API-Key' => @api_key }
|
22
|
+
@access_token = res['access_token']
|
23
|
+
res
|
24
|
+
end
|
25
|
+
|
26
|
+
def authorize(user,pass)
|
27
|
+
res = JSON.parse RestClient.post "https://auth.simperium.com/1/#{@app_id}/authorize/", { 'username' => user, 'password' => pass }.to_json, { 'X-Simperium-API-Key' => @api_key }
|
28
|
+
@access_token = res['access_token']
|
29
|
+
res
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](name)
|
33
|
+
if @access_token
|
34
|
+
Bucket.new @app_id, @access_token, name
|
35
|
+
else
|
36
|
+
raise "You need to authorize client first, try authorize(user,pass)"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Bucket
|
42
|
+
attr_accessor :name
|
43
|
+
|
44
|
+
def initialize(app_id, access_token, name)
|
45
|
+
@app_id = app_id
|
46
|
+
@access_token = access_token
|
47
|
+
@name = name
|
48
|
+
end
|
49
|
+
|
50
|
+
def index(params={})
|
51
|
+
JSON.parse RestClient.get "https://api.simperium.com/1/#{@app_id}/#{@name}/index", :params => { :data => params[:data], :mark => params[:mark], :limit => params[:limit], :since => params[:since] }, 'X-Simperium-Token' => @access_token
|
52
|
+
end
|
53
|
+
|
54
|
+
def new(data)
|
55
|
+
uid = (1..32).map{([*('a'..'z')]+[*('A'..'Z')]+[*(1..9)].map{|n|n.to_s}).instance_eval{self[rand(self.size)]}}.join
|
56
|
+
RestClient.post "https://api.simperium.com/1/#{@app_id}/#{@name}/i/#{uid}", data.to_json, { 'X-Simperium-Token' => @access_token }
|
57
|
+
uid
|
58
|
+
end
|
59
|
+
|
60
|
+
def [](object_id)
|
61
|
+
JSON.parse RestClient.get "https://api.simperium.com/1/#{@app_id}/#{@name}/i/#{object_id}", { 'X-Simperium-Token' => @access_token }
|
62
|
+
end
|
63
|
+
|
64
|
+
def []=(object_id, data)
|
65
|
+
JSON.parse RestClient.post "https://api.simperium.com/1/#{@app_id}/#{@name}/i/#{object_id}?response=1", data.to_json, { 'X-Simperium-Token' => @access_token }
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete(object_id)
|
69
|
+
RestClient.delete "https://api.simperium.com/1/#{@app_id}/#{@name}/i/#{object_id}", { 'X-Simperium-Token' => @access_token }
|
70
|
+
end
|
71
|
+
|
72
|
+
def changes(params={})
|
73
|
+
JSON.parse RestClient.get "https://api.simperium.com/1/#{@app_id}/#{@name}/all", :params => { :cv => params[:cv], :data => params[:data], :username => params[:username] }, 'X-Simperium-Token' => @access_token
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simperuby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Fayngersh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-09 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
requirement: &2152054440 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2152054440
|
26
|
+
description: A ruby client for the Simperium API
|
27
|
+
email: phunny.phacts@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/simperuby.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://rubygems.org/gems/hola
|
35
|
+
licenses: []
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.6.2
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: A ruby client for the Simperium API
|
58
|
+
test_files: []
|