kinto_box 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f41cad2d2d36c3deaf4c1804af203d22dfa86a59
4
- data.tar.gz: 19d61573448b09387cee1acd839c0e5be0f00565
3
+ metadata.gz: cd63b799d4e03bcc37de77e6e9669c29ca7f403e
4
+ data.tar.gz: e24e02470648c46c9b45ed357df0cff3e19f243b
5
5
  SHA512:
6
- metadata.gz: 48009280a182692c987a599f913847a2b96539d9394595bed282c6e01ed03f8136935f48155783b18c9beac23d06aac25e7f1b3e2fbdcc0233358b4364570481
7
- data.tar.gz: dfc240b5ac5970a1c1bcce4368b6f9f8930f9171fe36df89787918dcf8e2f04d69442ccf892b958ece98fa55e3ab8987e84db81d4d22d74d52002568f09b470a
6
+ metadata.gz: 300f47c897217f481d07ba653a1065693af058545b6c3b2fe27ccea491ab044a8c576b1b0f6518385d33e45fdf03fe801e54a00f6ce659fb61f675a78ce44760
7
+ data.tar.gz: 1f1b80c4135e17c9da8c81ead68ebcd593952159331dc4713ca4a3fce2036df92c668b367317d8e3f7c576a2e14b037afde2c0f4b1f53a41b9862dfd4c9baf08
data/README.md CHANGED
@@ -28,7 +28,7 @@ To use kinto_box, add `require 'kinto_box'` to your file.
28
28
  To connect to a kinto server, you can pass the username and password to the client
29
29
 
30
30
  ```
31
- kinto_client = KintoBox::KintoClient.new('https://kinto.dev.mozaws.net', {:username => 'token', :password => 'my-secret'})
31
+ kinto_client = KintoBox.new('https://kinto.dev.mozaws.net', {:username => 'token', :password => 'my-secret'})
32
32
  ```
33
33
 
34
34
  If no credentials are passed, the gem looks for `KINTO_API_TOKEN` environment variable. The environment variable should store the Base64 encoding of `username:password` string, for this to work.
@@ -105,7 +105,7 @@ To connect to a collection named `TestCollection`
105
105
  collection = bucket.collection('TestCollection')
106
106
  ```
107
107
 
108
- > Note: This does not create the collectiont nor check if the collection exists on the server.
108
+ > Note: This does not create the collection nor check if the collection exists on the server.
109
109
 
110
110
  To check if the collection exists use
111
111
 
@@ -143,6 +143,14 @@ To read from the collection
143
143
  records = collection.list_records
144
144
  ```
145
145
 
146
+ List records support filtering and sorting. It follows the convention described [here](http://kinto.readthedocs.io/en/stable/api/1.x/filtering.html) and [here](http://kinto.readthedocs.io/en/stable/api/1.x/sorting.html).
147
+
148
+ ```
149
+ records = collection.list_records('min_val=10','val')
150
+ ```
151
+
152
+ The above line will return all records where `val` is at least 10 and sorted ascending on the field `val`
153
+
146
154
  To delete all records from the collection
147
155
 
148
156
  ```
@@ -22,8 +22,13 @@ module KintoBox
22
22
  record.info
23
23
  end
24
24
 
25
- def list_records
26
- @kinto_client.get("#{@url_path}/records")
25
+ def list_records(filters = nil, sort = nil)
26
+ query_string = '?'
27
+ query_string += filters unless filters.nil?
28
+ query_string += '&' unless filters.nil? || sort.nil?
29
+ query_string += "_sort=#{sort}" unless sort.nil?
30
+ path = query_string == '?' ? "#{@url_path}/records" : "#{@url_path}/records#{query_string}"
31
+ @kinto_client.get(path)
27
32
  end
28
33
 
29
34
  def create_record(data)
@@ -1,3 +1,3 @@
1
1
  module KintoBox
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/kinto_box.rb CHANGED
@@ -5,11 +5,28 @@ require 'kinto_box/kinto_bucket'
5
5
  require 'base64'
6
6
 
7
7
  module KintoBox
8
+
9
+ # Initializes a new Kinto client.
10
+ #
11
+ # @param [String] server Url of the server without the version
12
+ # @param [Hash] options Optional parameter. If the hash contains :username and :password, it will be used to authenticate.
13
+ # `options` parameter can be used to pass in credentials. If no credentials are passed, it looks for KINTO_API_TOKEN environment variable
14
+ # @return [KintoBox::KintoClient] A kinto client object
15
+ def KintoBox.new(server, options = nil)
16
+ return KintoClient.new(server, options)
17
+ end
18
+
8
19
  class KintoClient
9
20
  include HTTParty
10
21
  headers 'Accept' => 'application/json', 'Content-Type' => 'application/json'
11
22
  format :json
12
23
 
24
+ # Initializes a new Kinto client.
25
+ #
26
+ # @param [String] server Url of the server without the version
27
+ # @param [Hash] options Optional parameter. If the hash contains :username and :password, it will be used to authenticate.
28
+ # `options` parameter can be used to pass in credentials. If no credentials are passed, it looks for KINTO_API_TOKEN environment variable
29
+ # @return [KintoBox::KintoClient] A kinto client object
13
30
  def initialize(server, options = nil)
14
31
  @server = server
15
32
  self.class.base_uri URI.join(@server, '/v1/').to_s
@@ -22,49 +39,92 @@ module KintoBox
22
39
  self.class.headers('Authorization' => "Basic #{@auth}")
23
40
  end
24
41
 
42
+ # Get reference to a bucket
43
+ #
44
+ # @param [String] bucket_id The id of the bucket
45
+ # @return [KintoBox::KintoBucket] A kinto bucket object
25
46
  def bucket (bucket_id)
26
47
  @bucket = KintoBucket.new(self, bucket_id)
27
48
  @bucket
28
49
  end
29
50
 
51
+ # Get server information
52
+ #
53
+ # @return [Hash] Server info as a hash
30
54
  def server_info
31
55
  get '/'
32
56
  end
33
57
 
58
+ # Get current user id
59
+ #
60
+ # @return [String] current user id
34
61
  def current_user_id
35
62
  server_info['user']['id']
36
63
  end
37
64
 
38
- # buckets
65
+ # List of buckets
66
+ #
67
+ # @return [Hash] with list of buckets
39
68
  def list_buckets
40
69
  get '/buckets'
41
70
  end
42
71
 
72
+ # Create a bucket
73
+ #
74
+ # @param [String] bucket_id The id of the bucket
75
+ # @return [KintoBox::KintoBucket] A kinto bucket object
43
76
  def create_bucket(bucket_id)
44
77
  put "/buckets/#{bucket_id}"
45
78
  bucket(bucket_id)
46
79
  end
47
80
 
81
+ # Delete all buckets
82
+ #
48
83
  def delete_buckets
49
84
  delete '/buckets'
50
85
  end
51
86
 
87
+ # Calls http PUT on path
88
+ #
89
+ # @params [String]path Url path
90
+ # @params [Hash] data to be sent in the body
91
+ # @return [Hash] response body
52
92
  def put(path, data = {})
53
93
  ResponseHandler.handle self.class.put(path, :body => data.to_json)
54
94
  end
55
95
 
96
+ # Calls http POST on path
97
+ #
98
+ # @params [String]path Url path
99
+ # @params [Hash] data to be sent in the body
100
+ # @return [Hash] response body
56
101
  def post(path, data = {})
57
102
  ResponseHandler.handle self.class.post(path, :body => data.to_json)
58
103
  end
59
104
 
105
+ # Calls http PATCH on path
106
+ #
107
+ # @params [String]path Url path
108
+ # @params [Hash] data to be sent in the body
109
+ # @return [Hash] response body
60
110
  def patch(path, data)
61
111
  ResponseHandler.handle self.class.patch(path, :body => data.to_json)
62
112
  end
63
113
 
114
+ # Calls http DELETE on path
115
+ #
116
+ # @params [String]path Url path
117
+ # @params [Hash] data to be sent in the body
118
+ # @return [Hash] response body
64
119
  def delete(path)
65
120
  ResponseHandler.handle self.class.delete(path)
66
121
  end
67
122
 
123
+ # Calls http GET on path
124
+ #
125
+ # @params [String]path Url path
126
+ # @params [Hash] data to be sent in the body
127
+ # @return [Hash] response body
68
128
  def get(path)
69
129
  ResponseHandler.handle self.class.get(path)
70
130
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kinto_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kavya Sukumar