analogbridge 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ module AnalogBridge
2
+ class Order < AnalogBridge::Base
3
+ def import_ready
4
+ AnalogBridge.get_resource("orders/import-ready")
5
+ end
6
+
7
+ def where(customer_id:, order_id: nil)
8
+ AnalogBridge.get_resource(
9
+ ["customers", customer_id, "orders", order_id].compact.join("/"),
10
+ )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module AnalogBridge
2
+ class Product < AnalogBridge::Base
3
+ def list
4
+ AnalogBridge.get_resource("products")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ require "json"
2
+
3
+ module AnalogBridge
4
+ class Response
5
+ attr_reader :response
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def parse
12
+ JSON.parse(response, object_class: ResponseObject)
13
+ rescue JSON::ParserError => error
14
+ ResponseObject.new(error: error, content: "")
15
+ end
16
+ end
17
+
18
+ class ResponseObject < OpenStruct; end
19
+ end
@@ -0,0 +1,3 @@
1
+ module AnalogBridge
2
+ VERSION = "0.1.0".freeze
3
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe AnalogBridge::Client do
4
+ describe ".get_resource" do
5
+ it "loads the resource via :get" do
6
+ stub_get_resource_request("ping")
7
+ resource = AnalogBridge.get_resource("ping")
8
+
9
+ expect(resource.data).to eq("Pong!")
10
+ end
11
+ end
12
+
13
+ describe ".post_resource" do
14
+ it "submit the request via :post" do
15
+ stub_post_ping_request
16
+ resource = AnalogBridge.post_resource("ping", {})
17
+
18
+ expect(resource.data).to eq("Pong!")
19
+ end
20
+ end
21
+
22
+ describe ".delete_resource" do
23
+ it "submits the request via :delete" do
24
+ stub_delete_ping_request
25
+ resource = AnalogBridge.delete_resource("ping")
26
+
27
+ expect(resource.data).to eq("Pong!")
28
+ end
29
+ end
30
+
31
+ def stub_get_resource_request(end_point)
32
+ stub_request(
33
+ :get, [AnalogBridge.configuration.api_host, end_point].join("/")
34
+ ).and_return(status: 200, body: JSON.generate(data: "Pong!"))
35
+ end
36
+
37
+ def stub_post_ping_request
38
+ stub_request(:post, "https://api.analogbridge.io/v1/ping").
39
+ to_return(status: 200, body: JSON.generate(data: "Pong!"))
40
+ end
41
+
42
+ def stub_delete_ping_request
43
+ stub_request(:delete, "https://api.analogbridge.io/v1/ping").
44
+ to_return(status: 200, body: JSON.generate(data: "Pong!"))
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+ require "analogbridge/configuration"
3
+
4
+ RSpec.describe AnalogBridge::Configuration do
5
+ describe ".configuration" do
6
+ it "returns the client configuration object" do
7
+ api_host = "https://api.analogbridge.io/v1"
8
+ configuration = AnalogBridge.configuration
9
+
10
+ expect(configuration.api_host).to eq(api_host)
11
+ end
12
+ end
13
+
14
+ describe "#secret_key" do
15
+ it "returns the configured secret key" do
16
+ AnalogBridge.configure do |config|
17
+ config.secret_key = "SECURE_SECRET_KEY"
18
+ end
19
+
20
+ expect(AnalogBridge.configuration.secret_key).to eq("SECURE_SECRET_KEY")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe AnalogBridge::Customer do
4
+ describe ".create" do
5
+ it "creates a new customer" do
6
+ stub_analogbridge_customer_create(customer_attributes)
7
+ customer = AnalogBridge::Customer.create(customer_attributes)
8
+
9
+ expect(customer.cus_id).not_to be_nil
10
+ expect(customer.metadata.user_id).to eq(123456)
11
+ expect(customer.email).to eq("demo@analogbridge.io")
12
+ end
13
+ end
14
+
15
+ describe ".find" do
16
+ it "retrieves the specified customer" do
17
+ customer_id = "cus_28b70539d2b10be293bdeb3c"
18
+ stub_analogbridge_customer_find(customer_id)
19
+ customer = AnalogBridge::Customer.find(customer_id)
20
+
21
+ expect(customer.cus_id).to eq(customer_id)
22
+ expect(customer.metadata.user_id).to eq(123456)
23
+ expect(customer.email).to eq("demo@analogbridge.io")
24
+ end
25
+ end
26
+
27
+ describe ".update" do
28
+ it "updates an existing customer details" do
29
+ customer_id = "cus_28b70539d2b10be293bdeb3c"
30
+ stub_analogbridge_customer_update(customer_id, customer_attributes)
31
+ customer = AnalogBridge::Customer.update(customer_id, customer_attributes)
32
+
33
+ expect(customer.cus_id).to eq(customer_id)
34
+ expect(customer.metadata.user_id).to eq(123456)
35
+ expect(customer.email).to eq("demo@analogbridge.io")
36
+ end
37
+ end
38
+
39
+ describe ".delete" do
40
+ it "deletes a specified customer" do
41
+ customer_id = "cus_28b70539d2b10be293bdeb3c"
42
+ stub_analogbridge_customer_delete(customer_id)
43
+ customer = AnalogBridge::Customer.delete(customer_id)
44
+
45
+ expect(customer.deleted).not_to be_nil
46
+ expect(customer.cus_id).to eq(customer_id)
47
+ expect(customer.deleted).not_to be_nil
48
+ end
49
+ end
50
+
51
+ describe ".list" do
52
+ it "retrieve all the customers" do
53
+ filters = { limit: "2", offset: "10" }
54
+ stub_analogbridge_customer_listting(filters)
55
+ customers = AnalogBridge::Customer.list(filters)
56
+
57
+ expect(customers.offset).to eq(10)
58
+ expect(customers.list.count).to eq(2)
59
+ expect(customers.total_count).to eq(102)
60
+ expect(customers.list.last.email).to eq("demo@analogbridge.io")
61
+ end
62
+ end
63
+
64
+ def customer_attributes
65
+ {
66
+ email: "demo@analogbridge.io",
67
+ shipping: {
68
+ first_name: "John",
69
+ last_name: "Smith",
70
+ address1: "3336 Commercial Ave",
71
+ city: "Northbrook",
72
+ state: "IL",
73
+ zip: "60062",
74
+ phone: "800-557-3508",
75
+ email: "demo@analogbridge.io",
76
+ },
77
+ metadata: {
78
+ user_id: "123456",
79
+ },
80
+ }
81
+ end
82
+ end
@@ -0,0 +1,22 @@
1
+ {
2
+ "cus_id": "cus_28b70539d2b10be293bdeb3c",
3
+ "auth": "long_auth_token",
4
+ "expires": 1481310922,
5
+ "email": "demo@analogbridge.io",
6
+ "shipping": {
7
+ "first_name": "John",
8
+ "last_name": "Smith",
9
+ "company": null,
10
+ "address1": "3336 Commercial Ave",
11
+ "address2": null,
12
+ "city": "Northbrook",
13
+ "state": "IL",
14
+ "zip": "60062",
15
+ "country": "US",
16
+ "phone": "800-557-3508",
17
+ "email": "demo@analogbridge.io"
18
+ },
19
+ "metadata": {
20
+ "user_id": 123456
21
+ }
22
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "status": "success",
3
+ "message": "Customer created successfully",
4
+ "data": {
5
+ "cus_id": "cus_28b70539d2b10be293bdeb3c",
6
+ "auth": "long_auth_token",
7
+ "expires": 1481310922,
8
+ "email": "demo@analogbridge.io",
9
+ "shipping": {
10
+ "first_name": "John",
11
+ "last_name": "Smith",
12
+ "company": null,
13
+ "address1": "3336 Commercial Ave",
14
+ "address2": null,
15
+ "city": "Northbrook",
16
+ "state": "IL",
17
+ "zip": "60062",
18
+ "country": "US",
19
+ "phone": "800-557-3508",
20
+ "email": "demo@analogbridge.io"
21
+ },
22
+ "metadata": {
23
+ "user_id": 123456
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "success": "success",
3
+ "message": "Customer deleted successfully",
4
+ "data" : {
5
+ "cus_id": "cus_28b70539d2b10be293bdeb3c",
6
+ "deleted": 1481325743
7
+ }
8
+ }
9
+
@@ -0,0 +1,26 @@
1
+ {
2
+ "offset": 10,
3
+ "limit": 20,
4
+ "total_count": 102,
5
+ "list": [
6
+ {
7
+ "cus_id": "cus_e6bd1537e138d2c3495cdb57",
8
+ "email": "test@test.com",
9
+ "metadata": {
10
+ "user_id": 123456,
11
+ "custom": {
12
+ "a": "2",
13
+ "b": "3"
14
+ }
15
+ }
16
+ },
17
+ {
18
+ "cus_id": "cus_d5026c9fee3c48b7d5809682",
19
+ "email": "demo@analogbridge.io",
20
+ "metadata": {
21
+ "user_id": 1234567
22
+ }
23
+ }
24
+ ]
25
+ }
26
+
@@ -0,0 +1,15 @@
1
+ [
2
+ {
3
+ "cus_id": "cus_5c5c5254882986ef6745",
4
+ "orders": [
5
+ "ord_4f66d77594318f53a4d5",
6
+ "ord_e6bd1537e138d2c3495c"
7
+ ]
8
+ },
9
+ {
10
+ "cus_id": "cus_3ab7aa6ec5feda6fe8a3",
11
+ "orders": [
12
+ "ord_fe310b878dc3313c3c2e"
13
+ ]
14
+ }
15
+ ]
@@ -0,0 +1,37 @@
1
+ {
2
+ "ord_id": "ord_fe310b878dc3313c3c2e",
3
+ "cus_id": "cus_28b70539d2b10be293bdeb3c",
4
+ "date": "2016-12-08 19:18:30",
5
+ "total": 89.47,
6
+ "subtotal": 89.47,
7
+ "shipping": 0,
8
+ "order_status": "Order Received from Client",
9
+ "approval_status": "Approved",
10
+ "instructions": "Transfer in numbered order",
11
+ "tracking": null,
12
+ "items": [
13
+ {
14
+ "id": 856962,
15
+ "date": "1993-09-17 00:00:00",
16
+ "title": "VHS #1",
17
+ "is_image": 0,
18
+ "is_video": 1,
19
+ "video_hq_url": "https://eterna.gomemorable.com/users/883/883_1000_Eugene-and-Boris-Concert_HQ.mp4",
20
+ "video_thumb_url": "https://eterna.gomemorable.com/users/883/883_1000_Eugene-and-Boris-Concert_thumb.jpg",
21
+ "image_hq_url": null,
22
+ "image_thumb_url": null
23
+ },
24
+ {
25
+ "id": 856963,
26
+ "date": "1995-09-23 00:00:00",
27
+ "title": "VHS #2",
28
+ "is_image": 0,
29
+ "is_video": 1,
30
+ "video_hq_url": "https://eterna.gomemorable.com/users/883/883_1000_1995-Jamaica-Cruise-_HQ.mp4",
31
+ "video_thumb_url": "https://eterna.gomemorable.com/users/883/883_1000_1995-Jamaica-Cruise-_thumb.jpg",
32
+ "image_hq_url": null,
33
+ "image_thumb_url": null
34
+ }
35
+ ]
36
+ }
37
+
@@ -0,0 +1,39 @@
1
+ [
2
+ {
3
+ "ord_id": "ord_fe310b878dc3313c3c2e",
4
+ "cus_id": "cus_28b70539d2b10be293bdeb3c",
5
+ "date": "2016-12-08 19:18:30",
6
+ "total": 89.47,
7
+ "subtotal": 89.47,
8
+ "shipping": 0,
9
+ "order_status": "Order Received from Client",
10
+ "approval_status": "Approved",
11
+ "instructions": "Transfer in numbered order",
12
+ "tracking": null,
13
+ "items": [
14
+ {
15
+ "id": 856962,
16
+ "date": "1993-09-17 00:00:00",
17
+ "title": "VHS #1",
18
+ "is_image": 0,
19
+ "is_video": 1,
20
+ "video_hq_url": "https://eterna.gomemorable.com/users/883/883_1000_Eugene-and-Boris-Concert_HQ.mp4",
21
+ "video_thumb_url": "https://eterna.gomemorable.com/users/883/883_1000_Eugene-and-Boris-Concert_thumb.jpg",
22
+ "image_hq_url": null,
23
+ "image_thumb_url": null
24
+ },
25
+ {
26
+ "id": 856963,
27
+ "date": "1995-09-23 00:00:00",
28
+ "title": "VHS #2",
29
+ "is_image": 0,
30
+ "is_video": 1,
31
+ "video_hq_url": "https://eterna.gomemorable.com/users/883/883_1000_1995-Jamaica-Cruise-_HQ.mp4",
32
+ "video_thumb_url": "https://eterna.gomemorable.com/users/883/883_1000_1995-Jamaica-Cruise-_thumb.jpg",
33
+ "image_hq_url": null,
34
+ "image_thumb_url": null
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "name": "35mm Slides",
4
+ "price": 0.69,
5
+ "url": "https://analogbridge.s3.amazonaws.com/images/format_35mmslides.jpg",
6
+ "product_id": 13,
7
+ "unit_name": "slide",
8
+ "category_name": "image"
9
+ },
10
+ {
11
+ "name": "Super 8mm Film",
12
+ "price": 14.5,
13
+ "url": "https://analogbridge.s3.amazonaws.com/images/format_super8.jpg",
14
+ "product_id": 16,
15
+ "unit_name": "50ft reel",
16
+ "category_name": "film"
17
+ }
18
+ ]
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe AnalogBridge::Order do
4
+ describe ".where" do
5
+ context "only customer_id provided" do
6
+ it "retrieves all orders for that customer" do
7
+ customer_id = "cus_28b70539d2b10be293bdeb3c"
8
+ stub_analogbridge_order_listing(customer_id: customer_id)
9
+ orders = AnalogBridge::Order.where(customer_id: customer_id)
10
+
11
+ expect(orders.first.items.count).to eq(2)
12
+ expect(orders.first.cus_id).to eq(customer_id)
13
+ expect(orders.first.items.first.id).not_to be_nil
14
+ end
15
+ end
16
+
17
+ context "both with customer_id and order_id" do
18
+ it "retrieve a specific order details" do
19
+ customer_id = "cus_28b70539d2b10be293bdeb3c"
20
+ order_id = "ord_fe310b878dc3313c3c2e"
21
+ stub_analogbridge_order_details(customer_id, order_id)
22
+ order = AnalogBridge::Order.where(
23
+ customer_id: customer_id, order_id: order_id,
24
+ )
25
+
26
+ expect(order.cus_id).to eq(customer_id)
27
+ expect(order.items.first.id).not_to be_nil
28
+ end
29
+ end
30
+ end
31
+
32
+ describe ".import_ready" do
33
+ it "retrieve all the import ready orders" do
34
+ stub_analogbridge_order_import_ready
35
+ orders = AnalogBridge::Order.import_ready
36
+
37
+ expect(orders.count).to eq(2)
38
+ expect(orders.first.cus_id).not_to be_nil
39
+ end
40
+ end
41
+ end