tincan-api 1.0.0 → 1.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.
- checksums.yaml +4 -4
- data/lib/tincan.rb +40 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c32c0ab4d57941b00135030ff38a27c64af3dc25
|
4
|
+
data.tar.gz: fe82042c353a55cae57feab55d020fb6e6b1ef58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa0d4f390dd840fbe9cf9202cecd6a853f9927ebefe9201bac056c76cfe968cadede3ad10adebed85a9193484f6bb8d763fb4859e97b63dc6698d8738b41278e
|
7
|
+
data.tar.gz: 768ec2bdeff8ea0ddb9004fb3d10ae8c78add47da8b8784e3a7b3d74b3ed351103cd97e736cb72e3f5d98822353bbc35326ef7fe41e07026eaec07066fa4ae76
|
data/lib/tincan.rb
CHANGED
@@ -1,20 +1,52 @@
|
|
1
1
|
["httparty", "json"].each(&method(:require))
|
2
2
|
|
3
|
+
# @author Charles Hollenbeck
|
3
4
|
class TinCan
|
4
5
|
include HTTParty
|
5
6
|
base_uri "apps.tincan.me"
|
6
7
|
|
8
|
+
# Initializes the starting variables to connect to the TinCan Storage API
|
9
|
+
#
|
10
|
+
# @param app_id [String] The ID for your TinCan Storage application
|
11
|
+
# @param app_key [String] The key for your TinCan Storage application
|
12
|
+
# @param app_name [String] The name for your TinCan Storage application
|
13
|
+
#
|
14
|
+
# @example TinCan.new("5e6a7e38c97b", "81aca0b3a200dd52bda8bca268ee68a8", "example")
|
7
15
|
def initialize(app_id, app_key, app_name)
|
16
|
+
# Initialize the starting variables to connect to the TinCan Storage API
|
8
17
|
@id = app_id
|
9
18
|
@key = app_key
|
10
19
|
@name = app_name
|
11
20
|
end
|
12
21
|
|
22
|
+
# Inserts data into a TinCan Storage Application
|
23
|
+
# @param query [Hash] A hash of the query you wish to send to the TinCan Storage API
|
24
|
+
# @example var.insert({:key => "value", :sec_key => "value"})
|
25
|
+
# @return [Boolean, String] True or the error
|
13
26
|
def insert(query) return read_response(req("insert", query.to_json)) end
|
27
|
+
|
28
|
+
# Finds data in a TinCan Storage Application
|
29
|
+
# @param query [Hash] A hash of the query you wish to send to the TinCan Storage API
|
30
|
+
# @example var.find({:query => {:key => "value"}, :options => {}}) Options are listed at http://apps.tincan.me/#manipulating
|
31
|
+
# @return [String] The returned data from the query or an error
|
14
32
|
def find(query) return read_response(req("find", query.to_json), true) end
|
33
|
+
|
34
|
+
# Updates data in a TinCan Storage Application
|
35
|
+
# @param query [Hash] A hash of the query you wish to send to the TinCan Storage API
|
36
|
+
# @example var.find({:query => {:key => "value"}, :data => {"$inc" => {:age => 1}}}) Options are listed at http://apps.tincan.me/#manipulating
|
37
|
+
# @return [Boolean, String] True or the error
|
15
38
|
def update(query) return read_response(req("update", query.to_json)) end
|
39
|
+
|
40
|
+
# Deletes data from a TinCan Storage Application
|
41
|
+
# @param query [Hash] A hash of the query you wish to send to the TinCan Storage API
|
42
|
+
# @example var.delete({:query => {:key => "value", :sec_key => "value"}, :options => {:drop => true}})
|
43
|
+
# @note As a safeguard, an empty query will NOT delete all documents. To erase ALL data in your application's database, you can drop it by using the query {:options => {:drop => true}}. You don't need to supply a query attribute, as it will be ignored if this option is present.
|
44
|
+
# @return [Boolean, String] True or the error
|
16
45
|
def delete(query) return read_response(req("remove", query.to_json)) end
|
17
46
|
|
47
|
+
# Validates your credentials with the TinCan Storage API
|
48
|
+
# @example var.validate
|
49
|
+
# @return [Boolean, String] True if it worked, an error otherwise. Errors can be: "NO SUCH APP" or "INVALID_CREDENTIALS"
|
18
50
|
def validate
|
19
51
|
return read_response(
|
20
52
|
self.class.get(
|
@@ -26,6 +58,10 @@ class TinCan
|
|
26
58
|
end
|
27
59
|
|
28
60
|
private
|
61
|
+
# Makes requests using HTTParty to the TinCan Storage API
|
62
|
+
# @param type [String] The type of query being made (insert|find|update|remove)
|
63
|
+
# @param query [String] The JSON Document to send to the TinCan Storage API
|
64
|
+
# @return [String] The response's body
|
29
65
|
def req(type, query)
|
30
66
|
return self.class.post(
|
31
67
|
"/#{@name}/#{type}",
|
@@ -35,6 +71,10 @@ class TinCan
|
|
35
71
|
).body
|
36
72
|
end
|
37
73
|
|
74
|
+
# Interprets the response from the TinCan Storage API
|
75
|
+
# @param res [String] The response body from the request
|
76
|
+
# @param has_data [Boolean] Optional parameter to tell it wether it has data being sent back in the response
|
77
|
+
# @return [Boolean, String] True if successful, a ruby hash of data if output has data or an error
|
38
78
|
def read_response(res, has_data = false)
|
39
79
|
res = JSON.parse(res)
|
40
80
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tincan-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Hollenbeck
|
@@ -70,3 +70,4 @@ signing_key:
|
|
70
70
|
specification_version: 4
|
71
71
|
summary: Ruby gem for the TinCan Storage API
|
72
72
|
test_files: []
|
73
|
+
has_rdoc:
|