kegbot_api 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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/.yardopts +1 -0
  6. data/CHANGELOG.md +18 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +178 -0
  10. data/Rakefile +1 -0
  11. data/kegbot_api.gemspec +30 -0
  12. data/lib/kegbot_api.rb +7 -0
  13. data/lib/kegbot_api/client.rb +39 -0
  14. data/lib/kegbot_api/client_helpers.rb +33 -0
  15. data/lib/kegbot_api/errors.rb +17 -0
  16. data/lib/kegbot_api/nouns/beverage.rb +23 -0
  17. data/lib/kegbot_api/nouns/drink.rb +32 -0
  18. data/lib/kegbot_api/nouns/image.rb +22 -0
  19. data/lib/kegbot_api/nouns/keg.rb +45 -0
  20. data/lib/kegbot_api/nouns/keg_size.rb +21 -0
  21. data/lib/kegbot_api/nouns/remote_rest_noun.rb +49 -0
  22. data/lib/kegbot_api/nouns/rest_noun.rb +36 -0
  23. data/lib/kegbot_api/nouns/rest_noun_attributes.rb +119 -0
  24. data/lib/kegbot_api/nouns/session.rb +32 -0
  25. data/lib/kegbot_api/nouns/tap.rb +31 -0
  26. data/lib/kegbot_api/rest_response.rb +76 -0
  27. data/lib/kegbot_api/version.rb +3 -0
  28. data/spec/beverage_spec.rb +44 -0
  29. data/spec/drink_spec.rb +88 -0
  30. data/spec/drinks.http +5416 -0
  31. data/spec/drinks_614.http +68 -0
  32. data/spec/drinks_999999.http +18 -0
  33. data/spec/example_1.rb +40 -0
  34. data/spec/example_2.rb +28 -0
  35. data/spec/examples_spec.rb +37 -0
  36. data/spec/image_spec.rb +33 -0
  37. data/spec/keg_spec.rb +131 -0
  38. data/spec/kegs.http +144 -0
  39. data/spec/kegs_4.http +46 -0
  40. data/spec/kegs_999999.http +18 -0
  41. data/spec/session_spec.rb +73 -0
  42. data/spec/sessions.http +601 -0
  43. data/spec/sessions_65.http +23 -0
  44. data/spec/sessions_999999.http +18 -0
  45. data/spec/spec_helper.rb +34 -0
  46. data/spec/tap_spec.rb +134 -0
  47. data/spec/taps.http +96 -0
  48. metadata +209 -0
@@ -0,0 +1,68 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.1 (Ubuntu)
3
+ Date: Thu, 27 Feb 2014 00:29:34 GMT
4
+ Content-Type: application/json
5
+ Transfer-Encoding: chunked
6
+ Connection: close
7
+ Vary: Accept-Encoding
8
+ Cache-Control: max-age=0
9
+
10
+ {
11
+ "object": {
12
+ "ticks": 0,
13
+ "user_id": "harry",
14
+ "url": "/drinks/614",
15
+ "duration": 0,
16
+ "volume_ml": 222.0,
17
+ "session_id": 65,
18
+ "keg": {
19
+ "volume_ml_remain": 21005.9,
20
+ "type_id": "1",
21
+ "url": "/kegs/3",
22
+ "spilled_ml": 0.0,
23
+ "start_time": "2014-01-31T23:11:38+00:00",
24
+ "percent_full": 35.80109725107757,
25
+ "id": 3,
26
+ "size_name": "half-barrel",
27
+ "end_time": "2014-01-31T23:11:38+00:00",
28
+ "online": true,
29
+ "size_id": 0,
30
+ "size_volume_ml": 58673.9
31
+ },
32
+ "session": {
33
+ "name": "",
34
+ "url": "/sessions/2014/2/27/65/",
35
+ "start_time": "2014-02-27T00:08:15+00:00",
36
+ "volume_ml": 222.0,
37
+ "end_time": "2014-02-27T03:08:15+00:00",
38
+ "id": 65
39
+ },
40
+ "user": {
41
+ "username": "harry",
42
+ "url": "/drinkers/harry/",
43
+ "image": {
44
+ "url": "/media/CACHE/images/pics/20140131231053-940cdc69ae8a495c960ea8ed893f3c8f/580d339d579ee75ce42f46e4c2334e2f.jpg",
45
+ "thumbnail_url": "/media/CACHE/images/pics/20140131231053-940cdc69ae8a495c960ea8ed893f3c8f/f72092fa383a61a40f2349d8aee2c075.jpg",
46
+ "user_id": "harry",
47
+ "time": "2014-01-31T23:10:53+00:00",
48
+ "original_url": "/media/pics/20140131231053-940cdc69ae8a495c960ea8ed893f3c8f.e"
49
+ },
50
+ "is_active": true
51
+ },
52
+ "time": "2014-02-27T00:08:15+00:00",
53
+ "images": [
54
+ {
55
+ "url": "/media/CACHE/images/pics/20140131231108-1cf7756d878e42f99f2e2918beb06d32/dcf6beaf3cb512cc6aa638a007988d15.jpg",
56
+ "thumbnail_url": "/media/CACHE/images/pics/20140131231108-1cf7756d878e42f99f2e2918beb06d32/38a46c4a8e786bc33de1bbabba514440.jpg",
57
+ "user_id": "harry",
58
+ "time": "2014-02-27T00:08:15+00:00",
59
+ "original_url": "/media/pics/20140131231108-1cf7756d878e42f99f2e2918beb06d32.7"
60
+ }
61
+ ],
62
+ "keg_id": 3,
63
+ "id": 614
64
+ },
65
+ "meta": {
66
+ "result": "ok"
67
+ }
68
+ }
@@ -0,0 +1,18 @@
1
+ HTTP/1.1 404 NOT FOUND
2
+ Server: nginx/1.4.1 (Ubuntu)
3
+ Date: Thu, 27 Feb 2014 23:05:37 GMT
4
+ Content-Type: application/json
5
+ Transfer-Encoding: chunked
6
+ Connection: close
7
+ Vary: Cookie
8
+ Cache-Control: max-age=0
9
+
10
+ {
11
+ "meta": {
12
+ "result": "error"
13
+ },
14
+ "error": {
15
+ "message": "No Drink matches the given query.",
16
+ "code": "NotFoundError"
17
+ }
18
+ }
@@ -0,0 +1,40 @@
1
+ require 'kegbot_api'
2
+
3
+ #
4
+ # Example use of the KegbotApi
5
+ #
6
+
7
+ client = KegbotApi::Client.new "http://demo.kegbot.org/api"
8
+
9
+ puts "KegbotApi Demo"
10
+ puts "http://demo.kegbot.org/api"
11
+ puts "--------------"
12
+
13
+ taps = client.Tap.all
14
+
15
+ puts "Taps: #{taps.length}"
16
+ puts "--------------"
17
+
18
+ taps.each_with_index do |tap, index|
19
+ puts "Tap #{index + 1}"
20
+ puts tap.name
21
+ puts "Online? #{tap.online?}"
22
+
23
+ if tap.online?
24
+ puts "On Tap: #{tap.keg.name}"
25
+
26
+ puts "Remaining: #{tap.keg.volume_ml_remaining}ml of #{tap.keg.volume_ml}ml"
27
+ puts '%.0f%' % tap.keg.percent_full
28
+ end
29
+
30
+ puts "--------------"
31
+ end
32
+
33
+ # Or you can find resources by ID...for example: Keg 1
34
+
35
+ puts "GET /kegs/1"
36
+ tap = client.Keg.find(1)
37
+
38
+ [:id, :name, :size_name, :volume_ml_remaining, :percent_full, :online?].each do |name|
39
+ puts "#{name} = #{tap.send(name)}"
40
+ end
@@ -0,0 +1,28 @@
1
+ require 'kegbot_api'
2
+
3
+ #
4
+ # REST endpoints and their corresponding KegbotApi classes/methods
5
+ #
6
+
7
+ client = KegbotApi::Client.new "http://demo.kegbot.org/api"
8
+
9
+ # /drinks
10
+ client.Drink.all
11
+
12
+ # /drinks/ID
13
+ client.Drink.find(1)
14
+
15
+ # /taps
16
+ client.Tap.all
17
+
18
+ # /kegs
19
+ client.Keg.all
20
+
21
+ # /kegs/ID
22
+ client.Keg.find(1)
23
+
24
+ # /sessions
25
+ client.Session.all
26
+
27
+ # /sessions/ID
28
+ client.Session.find(1)
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Example Use Cases" do
4
+ let(:default_baseurl) { TEST_API_BASEURL }
5
+ let(:client) { KegbotApi::Client.new default_baseurl }
6
+
7
+ it "Multiple Concurrent Clients" do
8
+ client_1_baseurl = "https://example1.kegbot.org/api"
9
+ client_2_baseurl = "https://example2.kegbot.org/api"
10
+
11
+ client1 = KegbotApi::Client.new client_1_baseurl
12
+ client2 = KegbotApi::Client.new client_2_baseurl
13
+
14
+ # Each Tap class should have a baseurl based on the client
15
+ expect(client1.Tap.client.base_url).to eq client_1_baseurl
16
+ expect(client2.Tap.client.base_url).to eq client_2_baseurl
17
+ end
18
+
19
+ describe "Example Scripts" do
20
+ before(:each) { FakeWeb.allow_net_connect = %r[^https?://demo\.kegbot\.org/api] }
21
+ after(:each) { FakeWeb.allow_net_connect = nil }
22
+
23
+ it "example_1.rb" do
24
+ script = File.join(File.dirname(__FILE__), "example_1.rb")
25
+ ruby = File.read(script)
26
+
27
+ Kernel::eval(ruby, nil, script)
28
+ end
29
+
30
+ it "example_2.rb" do
31
+ script = File.join(File.dirname(__FILE__), "example_2.rb")
32
+ ruby = File.read(script)
33
+
34
+ Kernel::eval(ruby, nil, script)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe KegbotApi::Image do
4
+ let(:client) { KegbotApi::Client.new TEST_API_BASEURL }
5
+ let(:attributes) do
6
+ {
7
+ "url" => "/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/0d8521a4eef37663218db5aef284089e.jpg",
8
+ "thumbnail_url" => "/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/1c3f0a2375704ebe62a82aec658b5287.jpg",
9
+ "original_url" => "/media/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90.e",
10
+ "time" => "2014-01-31T23:10:53+00:00"
11
+ }
12
+ end
13
+
14
+ describe "Image Methods" do
15
+ subject { client.Image.new attributes }
16
+
17
+ it "time" do
18
+ expect(subject.time).to eq DateTime.iso8601("2014-01-31T23:10:53+00:00").to_time
19
+ end
20
+
21
+ it "url" do
22
+ expect(subject.url).to eq 'https://example.kegbot.org/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/0d8521a4eef37663218db5aef284089e.jpg'
23
+ end
24
+
25
+ it "thumbnail_url" do
26
+ expect(subject.thumbnail_url).to eq 'https://example.kegbot.org/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/1c3f0a2375704ebe62a82aec658b5287.jpg'
27
+ end
28
+
29
+ it "to_s container 'KegbotApi::Image'" do
30
+ expect(subject.to_s).to include 'KegbotApi::Image'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe KegbotApi::Keg do
4
+ let(:client) { KegbotApi::Client.new TEST_API_BASEURL }
5
+
6
+ describe "Class Methods" do
7
+ let(:all) { client.Keg.all }
8
+
9
+ describe "::all" do
10
+ describe "Is Array Like" do
11
+ it "responds_to length" do
12
+ expect(all).to respond_to :length
13
+ end
14
+
15
+ it "responds_to []" do
16
+ expect(all).to respond_to :[]
17
+ end
18
+ end
19
+
20
+ it "length == 4" do
21
+ expect(all.length).to eq 4
22
+ end
23
+
24
+ it "first.id == 4" do
25
+ expect(all.first.id).to eq 4
26
+ end
27
+ end
28
+
29
+ describe "::find(4)" do
30
+ subject { client.Keg.find 4 }
31
+
32
+ it "Succeeds" do
33
+ expect(subject).to_not be nil
34
+ end
35
+
36
+ it "id == 4" do
37
+ expect(subject.id).to eq 4
38
+ end
39
+
40
+ it "raise NotFoundError on invalid ID" do
41
+ expect { client.Keg.find 999999 }.to raise_error(KegbotApi::NotFoundError)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "Instance Methods" do
47
+ subject { client.Keg.first }
48
+
49
+ it "id == 4" do
50
+ expect(subject.id).to eq 4
51
+ end
52
+
53
+ it "percent_full == 37.149226487416044" do
54
+ expect(subject.percent_full).to be_within(1e-6).of 37.149226487416044
55
+ end
56
+
57
+ it "volume_ml_remain == 21796.9" do
58
+ expect(subject.volume_ml_remain).to be_within(1e-6).of 21796.9
59
+ expect(subject.volume_ml_remaining).to be_within(1e-6).of 21796.9
60
+ end
61
+
62
+ it "spilled_ml == 0.0" do
63
+ expect(subject.spilled_ml).to be_within(1e-6).of 0.0
64
+ end
65
+
66
+ it "start_time == '2014-01-31T23:11:42+00:00'" do
67
+ expect(subject.start_time).to eq DateTime.iso8601('2014-01-31T23:11:42+00:00').to_time
68
+ end
69
+
70
+ it "start_time is Time" do
71
+ expect(subject.start_time).to be_kind_of Time
72
+ end
73
+
74
+ it "end_time == '2014-01-31T23:11:42+00:00'" do
75
+ expect(subject.end_time).to eq DateTime.iso8601('2014-01-31T23:11:42+00:00').to_time
76
+ end
77
+
78
+ it "end_time is Time" do
79
+ expect(subject.end_time).to be_kind_of Time
80
+ end
81
+
82
+ it "online? == true" do
83
+ expect(subject).to be_online
84
+ end
85
+
86
+ it "name == 'Drake's 1500'" do
87
+ expect(subject.name).to eq "Drake's 1500"
88
+ end
89
+
90
+ it "volume_ml == 58673.9" do
91
+ expect(subject.volume_ml).to eq 58673.9
92
+ end
93
+
94
+ it "size_name == 'half-barrel'" do
95
+ expect(subject.size_name).to eq "half-barrel"
96
+ end
97
+
98
+ it "to_s containts 'KegbotApi::Keg'" do
99
+ expect(subject.to_s).to include 'KegbotApi::Keg'
100
+ end
101
+ end
102
+
103
+ describe "Associations" do
104
+ describe "type/beverage" do
105
+ subject { client.Keg.first }
106
+
107
+ it "Works" do
108
+ expect(subject.beverage).to_not be nil
109
+ end
110
+
111
+ it "aka type" do
112
+ expect(subject.type).to_not be nil
113
+ end
114
+
115
+ it "beverage.name" do
116
+ expect(subject.beverage.name).to_not be nil
117
+ end
118
+ end
119
+
120
+ describe "size" do
121
+ subject { client.Keg.first }
122
+
123
+ it "Works" do
124
+ expect(subject.size).to_not be nil
125
+ end
126
+ end
127
+ end
128
+
129
+ pending "keg.drinks"
130
+ pending "keg.sessions"
131
+ end
@@ -0,0 +1,144 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.1 (Ubuntu)
3
+ Date: Thu, 27 Feb 2014 00:24:53 GMT
4
+ Content-Type: application/json
5
+ Transfer-Encoding: chunked
6
+ Connection: close
7
+ Vary: Accept-Encoding
8
+ Cache-Control: max-age=0
9
+
10
+ {
11
+ "objects": [
12
+ {
13
+ "volume_ml_remain": 21796.9,
14
+ "type_id": "4",
15
+ "url": "/kegs/4",
16
+ "spilled_ml": 0.0,
17
+ "start_time": "2014-01-31T23:11:42+00:00",
18
+ "percent_full": 37.149226487416044,
19
+ "size_id": 0,
20
+ "size_name": "half-barrel",
21
+ "end_time": "2014-01-31T23:11:42+00:00",
22
+ "online": true,
23
+ "type": {
24
+ "name": "Drake's 1500",
25
+ "style_id": "0",
26
+ "image": {
27
+ "url": "/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/0d8521a4eef37663218db5aef284089e.jpg",
28
+ "thumbnail_url": "/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/1c3f0a2375704ebe62a82aec658b5287.jpg",
29
+ "original_url": "/media/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90.e",
30
+ "time": "2014-01-31T23:10:53+00:00"
31
+ },
32
+ "abv": 0.0,
33
+ "brewer_id": "3",
34
+ "id": "4"
35
+ },
36
+ "id": 4,
37
+ "size_volume_ml": 58673.9,
38
+ "size": {
39
+ "volume_ml": 58673.9,
40
+ "id": 0,
41
+ "name": "half-barrel"
42
+ }
43
+ },
44
+ {
45
+ "volume_ml_remain": 21005.9,
46
+ "type_id": "1",
47
+ "url": "/kegs/3",
48
+ "spilled_ml": 0.0,
49
+ "start_time": "2014-01-31T23:11:38+00:00",
50
+ "percent_full": 35.80109725107757,
51
+ "size_id": 0,
52
+ "size_name": "half-barrel",
53
+ "end_time": "2014-01-31T23:11:38+00:00",
54
+ "online": true,
55
+ "type": {
56
+ "name": "Anchor Steam",
57
+ "style_id": "0",
58
+ "image": {
59
+ "url": "/media/CACHE/images/pics/20140131231053-a36a6b7cd54d461c97c63339c6762bf0/c7a226b5122af9ea4c3b9d72cdc4c46d.jpg",
60
+ "thumbnail_url": "/media/CACHE/images/pics/20140131231053-a36a6b7cd54d461c97c63339c6762bf0/704675543d5b73232c8a51f16435ea9d.jpg",
61
+ "original_url": "/media/pics/20140131231053-a36a6b7cd54d461c97c63339c6762bf0.e",
62
+ "time": "2014-01-31T23:10:53+00:00"
63
+ },
64
+ "abv": 0.0,
65
+ "brewer_id": "1",
66
+ "id": "1"
67
+ },
68
+ "id": 3,
69
+ "size_volume_ml": 58673.9,
70
+ "size": {
71
+ "volume_ml": 58673.9,
72
+ "id": 0,
73
+ "name": "half-barrel"
74
+ }
75
+ },
76
+ {
77
+ "volume_ml_remain": 173.90000000000146,
78
+ "type_id": "4",
79
+ "url": "/kegs/2",
80
+ "spilled_ml": 0.0,
81
+ "start_time": "2013-12-18T20:49:00+00:00",
82
+ "percent_full": 0.29638391175633705,
83
+ "size_id": 0,
84
+ "size_name": "half-barrel",
85
+ "end_time": "2014-01-31T23:10:53+00:00",
86
+ "online": false,
87
+ "type": {
88
+ "name": "Drake's 1500",
89
+ "style_id": "0",
90
+ "image": {
91
+ "url": "/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/0d8521a4eef37663218db5aef284089e.jpg",
92
+ "thumbnail_url": "/media/CACHE/images/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90/1c3f0a2375704ebe62a82aec658b5287.jpg",
93
+ "original_url": "/media/pics/20140131231053-e6ce61eda0a841edad856fe2679c8f90.e",
94
+ "time": "2014-01-31T23:10:53+00:00"
95
+ },
96
+ "abv": 0.0,
97
+ "brewer_id": "3",
98
+ "id": "4"
99
+ },
100
+ "id": 2,
101
+ "size_volume_ml": 58673.9,
102
+ "size": {
103
+ "volume_ml": 58673.9,
104
+ "id": 0,
105
+ "name": "half-barrel"
106
+ }
107
+ },
108
+ {
109
+ "volume_ml_remain": 80.90000000000146,
110
+ "type_id": "3",
111
+ "url": "/kegs/1",
112
+ "spilled_ml": 0.0,
113
+ "start_time": "2013-12-18T20:10:00+00:00",
114
+ "percent_full": 0.13788072720579586,
115
+ "size_id": 0,
116
+ "size_name": "half-barrel",
117
+ "end_time": "2014-01-31T23:10:53+00:00",
118
+ "online": false,
119
+ "type": {
120
+ "name": "Drake's Blonde",
121
+ "style_id": "0",
122
+ "image": {
123
+ "url": "/media/CACHE/images/pics/20140131231053-5b277158667f4f34a63b6a4d627fbc02/50783fc343a86611edcea5ff3e196f8f.jpg",
124
+ "thumbnail_url": "/media/CACHE/images/pics/20140131231053-5b277158667f4f34a63b6a4d627fbc02/da13742b4a6747654131b79ac261a3ef.jpg",
125
+ "original_url": "/media/pics/20140131231053-5b277158667f4f34a63b6a4d627fbc02.e",
126
+ "time": "2014-01-31T23:10:53+00:00"
127
+ },
128
+ "abv": 0.0,
129
+ "brewer_id": "3",
130
+ "id": "3"
131
+ },
132
+ "id": 1,
133
+ "size_volume_ml": 58673.9,
134
+ "size": {
135
+ "volume_ml": 58673.9,
136
+ "id": 0,
137
+ "name": "half-barrel"
138
+ }
139
+ }
140
+ ],
141
+ "meta": {
142
+ "result": "ok"
143
+ }
144
+ }