purzelrakete-boomloop 0.0.2 → 0.0.3

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.
data/README.txt CHANGED
@@ -20,17 +20,14 @@ a 3 step process.
20
20
 
21
21
  == Example API Call
22
22
 
23
- Once you have authorized your client, you can make the first API call like this:
23
+ Once you have authorized your client, you can make the first API client call.
24
24
 
25
- client = Boomloop::Authentication::Client.new("api", Boomloop::Authentication::Store::YAMLStore.new)
26
- connection = client.create_accesstoken
27
- events = connection.get("/events").body
25
+ require 'boomloop'
26
+ events = Boomloop::Resources::Event.index(:order => :proximity, :origin => "opernplatz, frankfurt am main")
28
27
 
29
- This returns the raw XML. We'll see how to get Event Objects next.
28
+ This returns a list of the top 10 closest upcoming events, where the origin is opernplatz, frankfurt am main.
30
29
 
31
- The Client takes two arguments - a config key, and an authentication name. When you authorize using
32
- the boomloop script, a config key 'api' is created in the YAMLStore. This holds your the access
33
- tokens so that you don't need to negotiate them every time you want to make a request.
30
+ For a full description of options, see boomloop.com/api. The ruby lib is just a thin wrapper around the REST api, so what goes up rthere, must come down here ;)
34
31
 
35
32
 
36
33
 
data/bin/boomloop CHANGED
@@ -33,11 +33,11 @@ error(parser) unless options.secret && options.key
33
33
 
34
34
  # negotiate the tokens
35
35
  client = Boomloop::Authentication::Client.new("api", Boomloop::Authentication::Store::YAMLStore.new)
36
- request_token = client.consume(options.key, options.secret) rescue error("Invalid. Check your credentials at http://boomloop.com/oauth/applications.")
36
+ request_token = client.consume(options.key, options.secret) rescue error("Invalid. Check your credentials at #{ Boomloop::Resources::Base.api_base }oauth/applications.")
37
37
  puts "\nalmost ready! go to #{ request_token.authorize_url }\n\n press enter when you're done... <waiting>\n"
38
38
 
39
39
  while !@access_token && gets
40
40
  @access_token = client.activate rescue nil
41
41
  end
42
42
 
43
- puts "your keys have been activated. you're ready to use the api. \n\n"
43
+ puts "your keys have been activated. you're ready to use the api. \n\n"
@@ -1,3 +1,8 @@
1
+ =begin
2
+ The Client takes two arguments - a config key, and an authentication name. When you authorize using
3
+ the boomloop script, a config key 'api' is created in the YAMLStore. This holds your the access
4
+ tokens so that you don't need to negotiate them every time you want to make a request.
5
+ =end
1
6
  module Boomloop
2
7
  module Authentication
3
8
  class Client
@@ -1,12 +1,14 @@
1
1
  module Boomloop
2
2
  module Resources
3
3
  class Base < ::OpenStruct
4
- API_BASE = 'http://api.boomloop.com/'
5
-
6
4
  class << self
7
5
  attr_accessor :connection
8
6
  end
9
7
 
8
+ def self.api_base
9
+ ENV["BOOMLOOP_API_BASE"] || 'http://api.boomloop.com/'
10
+ end
11
+
10
12
  def self.connection
11
13
  @@connection ||= init
12
14
  end
@@ -45,23 +47,37 @@ module Boomloop
45
47
 
46
48
  # REST methods
47
49
  def self.index(params = {})
48
- url = API_BASE + self.plural
50
+ url = api_base + self.plural
49
51
  url += "?#{ params.to_query }" unless params.empty?
50
52
  xml = connection.get(url)
51
- attrs = Hash.from_xml(xml)
53
+
54
+ attrs = from_xml(xml)
52
55
  construct_resource_collection(attrs)
53
56
  end
54
57
 
55
58
  def self.show(url)
56
59
  xml = connection.get(url)
57
- attrs = Hash.from_xml(xml)
60
+ attrs = from_xml(xml)
58
61
  self.new(attrs[self.singular])
59
62
  end
60
63
 
61
64
  def self.create(resource)
62
- url = API_BASE + self.plural
65
+ url = api_base + self.plural
63
66
  xml = connection.post(url, resource.to_hash.to_query)
64
- self.new(Hash.from_xml(xml)[self.singular])
67
+ self.new(from_xml(xml)[self.singular])
68
+ end
69
+
70
+ def self.from_xml(response)
71
+ xml = nil
72
+ begin
73
+ xml = Hash.from_xml(response)
74
+ rescue Exception => e
75
+ raise Boomloop::APIError.new("Response from boomloop could not be parsed. Response was: \n\n #{ response }")
76
+ end
77
+
78
+ raise Boomloop::APIError.new("There was a problem with your request: \n\n #{ response }") if xml["errors"]
79
+
80
+ xml
65
81
  end
66
82
 
67
83
  def self.construct_resource_collection(attrs)
@@ -16,32 +16,32 @@ context "a boomloop resource" do
16
16
  monster.to_hash.should.equal qualities
17
17
  end
18
18
 
19
- specify "should be showable when calling Boomloop::Resources::Monster.show('http://api.boomloop.com/monsters/fred')" do
20
- @connection.expects(:get).with("http://api.boomloop.com/monsters/fred").at_least_once.returns(%Q[
19
+ specify "should be showable when calling Boomloop::Resources::Monster.show('#{ Boomloop::Resources::Base.api_base }monsters/fred')" do
20
+ @connection.expects(:get).with("#{ Boomloop::Resources::Base.api_base }monsters/fred").at_least_once.returns(%Q[
21
21
  <monster>
22
- <resource_url>http://api.boomloop.com/monsters/fred</resource_url>
22
+ <resource_url>#{ Boomloop::Resources::Base.api_base }monsters/fred</resource_url>
23
23
  <size>huge</size>
24
24
  <affect>sanguine</affect>
25
25
  <name>fred</name>
26
26
  </monster>
27
27
  ])
28
28
 
29
- monster = Boomloop::Resources::Monster.show('http://api.boomloop.com/monsters/fred')
29
+ monster = Boomloop::Resources::Monster.show("#{ Boomloop::Resources::Base.api_base }monsters/fred")
30
30
  monster.name.should.equal "fred"
31
31
  end
32
32
 
33
33
  specify "should be listable when calling Boomloop::Resources::Monster.index" do
34
- @connection.expects(:get).with("http://api.boomloop.com/monsters").at_least_once.returns(%Q[
34
+ @connection.expects(:get).with("#{ Boomloop::Resources::Base.api_base }monsters").at_least_once.returns(%Q[
35
35
  <monsters>
36
36
  <monster>
37
- <resource_url>http://api.boomloop.com/monsters/fred</resource_url>
37
+ <resource_url>#{ Boomloop::Resources::Base.api_base }monsters/fred</resource_url>
38
38
  <size>huge</size>
39
39
  <affect>sanguine</affect>
40
40
  <name>fred</name>
41
41
  </monster>
42
42
 
43
43
  <monster>
44
- <resource_url>http://api.boomloop.com/monsters/simon</resource_url>
44
+ <resource_url>#{ Boomloop::Resources::Base.api_base }monsters/simon</resource_url>
45
45
  <size>middling</size>
46
46
  <affect>indifferent</affect>
47
47
  <name>simon</name>
@@ -54,10 +54,10 @@ context "a boomloop resource" do
54
54
  end
55
55
 
56
56
  specify "should be listable when calling Boomloop::Resources::Monster.index and there is only one result" do
57
- @connection.expects(:get).with("http://api.boomloop.com/monsters").at_least_once.returns(%Q[
57
+ @connection.expects(:get).with("#{ Boomloop::Resources::Base.api_base }monsters").at_least_once.returns(%Q[
58
58
  <monsters>
59
59
  <monster>
60
- <resource_url>http://api.boomloop.com/monsters/fred</resource_url>
60
+ <resource_url>#{ Boomloop::Resources::Base.api_base }monsters/fred</resource_url>
61
61
  <size>huge</size>
62
62
  <affect>sanguine</affect>
63
63
  <name>fred</name>
@@ -70,10 +70,10 @@ context "a boomloop resource" do
70
70
  end
71
71
 
72
72
  specify "should be listable with attributes when calling Boomloop::Resources::Monster.index(:affect => :sanguine)" do
73
- @connection.expects(:get).with("http://api.boomloop.com/monsters?affect=sanguine").at_least_once.returns(%Q[
73
+ @connection.expects(:get).with("#{ Boomloop::Resources::Base.api_base }monsters?affect=sanguine").at_least_once.returns(%Q[
74
74
  <monsters>
75
75
  <monster>
76
- <resource_url>http://api.boomloop.com/monsters/fred</resource_url>
76
+ <resource_url>#{ Boomloop::Resources::Base.api_base }monsters/fred</resource_url>
77
77
  <size>huge</size>
78
78
  <affect>sanguine</affect>
79
79
  <name>fred</name>
@@ -86,10 +86,10 @@ context "a boomloop resource" do
86
86
  end
87
87
 
88
88
  specify "should be savable when calling .save on a Monster instance" do
89
- intended_resource_url = 'http://api.boomloop.com/monsters/samuel'
89
+ intended_resource_url = "#{ Boomloop::Resources::Base.api_base }monsters/samuel"
90
90
  intended_attributes = { :size => :laughable, :affect => :mordant, :name => "samuel" }
91
91
 
92
- @connection.expects(:post).with("http://api.boomloop.com/monsters", intended_attributes.to_query).at_least_once.returns(%Q[
92
+ @connection.expects(:post).with("#{ Boomloop::Resources::Base.api_base }monsters", intended_attributes.to_query).at_least_once.returns(%Q[
93
93
  <monster>
94
94
  <resource_url>#{ intended_resource_url }</resource_url>
95
95
  <size>laughable</size>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purzelrakete-boomloop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rany Keddo