celery_api 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b993b4bbeabfb0ea78df6e5f172d6b201b3672bf
4
- data.tar.gz: 69a75b093c226864dce5a23c0abfb57a9cd3a343
3
+ metadata.gz: d34969976d629b41ad78a80ad06084c68070d30d
4
+ data.tar.gz: 2f8b4335c27114f6dfdb5a6f40b7f49066207183
5
5
  SHA512:
6
- metadata.gz: 7f6a1556332b0d854ef9d77b9d0eee7d3c538197bf8bf689a7503bd87dcb13a1e3eec50d62a3e26d51dd0e346388b9cc1e835eaf8690ab68ffc4d682908a9422
7
- data.tar.gz: a527b8fa9049885d67dc2087147abce34cbe14b5ac810b8eb35a300813a7fec0ec4297b6eaf6faba2571e35fcf5c05414485cb1040b0d6b4bbe19a2a357bc674
6
+ metadata.gz: 4f9f2a6cf4dcf2368fa78e54774a7e7eb2d90358ea3a32dc95e58dc755ed03291ddb1bf6a37606c1a7fbc2aa35440911cc9c237134044f48291dbd83b1405554
7
+ data.tar.gz: 6de6aa55f33c0185a43029c4d7c366ee01c11b39fce2a2d13ae44703ba0a1a990d67c7fc19744d0f3a740dc31247404dde87e0766893accd16c8d697957cad58
@@ -13,6 +13,24 @@ module Celery
13
13
  def build_collection(collection)
14
14
  collection.map { |item| self.new(item) }
15
15
  end
16
+
17
+ def get(id)
18
+ endpoint_resource = self::ENDPOINT_RESOURCE
19
+ endpoint_path = Celery.endpoint + endpoint_resource + "/" + id
20
+ options = Celery.parameterize_options
21
+ response = HTTParty.get("#{endpoint_path}?#{options}")
22
+
23
+ self.new(response[self::ENDPOINT_RESOURCE_SINGULAR])
24
+ end
25
+
26
+ def create(attrs={})
27
+ endpoint_resource = self::ENDPOINT_RESOURCE
28
+ endpoint_path = Celery.endpoint + endpoint_resource
29
+ options = Celery.parameterize_options
30
+ response = HTTParty.post("#{endpoint_path}?#{options}", body: { product: attrs }.to_json, headers: { 'Content-Type' => 'application/json' })
31
+
32
+ self.new(response[self::ENDPOINT_RESOURCE_SINGULAR])
33
+ end
16
34
  end
17
35
 
18
36
  end
@@ -2,7 +2,8 @@ module Celery
2
2
 
3
3
  class Product < Base
4
4
 
5
- ENDPOINT_RESOURCE = "products"
5
+ ENDPOINT_RESOURCE = "products"
6
+ ENDPOINT_RESOURCE_SINGULAR = "product"
6
7
 
7
8
  extend Celery::EndpointMethods
8
9
 
@@ -17,6 +18,26 @@ module Celery
17
18
  @_id = id
18
19
  @id = id
19
20
  end
21
+
22
+ def update(attrs={})
23
+ update_local_object(attrs)
24
+ endpoint_path = Celery.endpoint + "products" + "/" + self.id
25
+ options = Celery.parameterize_options
26
+ response = HTTParty.put("#{endpoint_path}?#{options}", body: { product: attrs }.to_json, headers: { 'Content-Type' => 'application/json' })
27
+
28
+ return true if response['product']
29
+ end
30
+
31
+ def update_local_object(attrs)
32
+ attrs.each { |key, value| self.send("#{key}=", value) }
33
+ end
34
+
35
+ def destroy
36
+ endpoint_path = Celery.endpoint + "products" + "/" + self.id
37
+ options = Celery.parameterize_options
38
+ response = HTTParty.delete("#{endpoint_path}?#{options}")
39
+ return response['status']
40
+ end
20
41
  end
21
42
 
22
43
  end
@@ -1,3 +1,3 @@
1
1
  module Celery
2
- VERSION = "0.0.5".freeze
2
+ VERSION = "0.0.6".freeze
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Celery::Product do
3
+ describe Celery::Product, 'class methods' do
4
+ let!(:products) { Celery::Product.all }
4
5
  it 'returns all the products from the endpoint' do
5
- products = Celery::Product.all
6
6
  expect(products).to be_kind_of Array
7
7
  expect(products.first).to be_kind_of Celery::Product
8
8
  end
@@ -13,4 +13,38 @@ describe Celery::Product do
13
13
  expect(products.first).to be_kind_of Celery::Product
14
14
  expect(products.first.id).to eq("1234")
15
15
  end
16
+
17
+ it 'gets 1 product by id' do
18
+ product = products.first
19
+ expect(Celery::Product.get(product.id)).to be_kind_of Celery::Product
20
+ expect(Celery::Product.get(product.id).id).to eq(product.id)
21
+ end
22
+
23
+ it 'creates a new product' do
24
+ attrs = {
25
+ name: Faker::Lorem.word,
26
+ price: 10000,
27
+ deposit: 1000,
28
+ options: []
29
+ }
30
+
31
+ product = Celery::Product.create(attrs)
32
+ expect(product).to be_kind_of Celery::Product
33
+ expect(Celery::Product.get(product.id).id).to eq(product.id)
34
+ end
35
+ end
36
+
37
+ describe Celery::Product, 'instance methods' do
38
+ let!(:products) { Celery::Product.all }
39
+ let!(:product) { products.first }
40
+
41
+ it 'updates the product attributes' do
42
+ name = Faker::Lorem.word
43
+ expect(product.update(name: name)).to eq(true)
44
+ expect(product.name).to eq(name)
45
+ end
46
+
47
+ it 'deletes a product' do
48
+ expect(product.destroy).to eq(true)
49
+ end
16
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celery_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Chavez