almodovar 0.0.1 → 0.1.0

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 (3) hide show
  1. data/README.rdoc +33 -11
  2. data/lib/almodovar.rb +13 -6
  3. metadata +3 -3
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  =Almodovar
2
2
 
3
- Almodovar is a client for BeBanjo Movida API written in Ruby
3
+ Almodovar is a client for BeBanjo's Movida API written in Ruby
4
4
 
5
5
  ==Getting started
6
6
 
@@ -38,20 +38,42 @@ Ok. Let's see what we have under _platforms_
38
38
  <link href="http://movida.example.com/api/platforms/6/schedule" rel="schedule"/>
39
39
  </platform>]
40
40
 
41
- Now, show me the _schedule_ of the first _platform_:
42
-
43
- >> movida.platforms.first.schedule
41
+ Now, show me the _schedule_ of a _title_ given its external id:
42
+
43
+ >> movida.titles(:external_id => "C5134350003").first.schedule(:expand => :schedulings)
44
44
  => <schedule>
45
- <link href="http://movida.example.com/api/platforms/1/schedule/schedulings" rel="schedulings"/>
46
- <link href="http://movida.example.com/api/platforms/1" rel="platform"/>
45
+ <link href="http://staging.schedule.bebanjo.net/api/titles/498/schedule/schedulings" rel="schedulings"><schedulings type="array">
46
+ <scheduling>
47
+ <id type="integer">1122</id>
48
+ <put-up type="datetime">2010-04-17T00:00:00Z</put-up>
49
+ <take-down type="datetime">2010-06-17T00:00:00Z</take-down>
50
+ <scheduling-type>archive</scheduling-type>
51
+ <link href="http://staging.schedule.bebanjo.net/api/title_groups/129" rel="title_group"/>
52
+ <link href="http://staging.schedule.bebanjo.net/api/titles/498" rel="title"/>
53
+ </scheduling>
54
+ </schedulings>
55
+ </link>
56
+ <link href="http://staging.schedule.bebanjo.net/api/titles/498" rel="title"/>
47
57
  </schedule>
48
58
 
49
- Next, explore and see the {docs of the API}[http://wiki.github.com/bebanjo/almodovar/] to know about other resources.
59
+ Of course, once you've got the URL of a resource, the next time you don't need to navigate from the root of the API. You can (should!) start from the resource URL:
60
+
61
+ >> schedulings = Almodovar::Resource("http://staging.schedule.bebanjo.net/api/titles/498/schedule/schedulings", auth)
62
+ => [<scheduling>
63
+ <id type="integer">1122</id>
64
+ <put-up type="datetime">2010-04-17T00:00:00Z</put-up>
65
+ <take-down type="datetime">2010-06-17T00:00:00Z</take-down>
66
+ <scheduling-type>archive</scheduling-type>
67
+ <link href="http://staging.schedule.bebanjo.net/api/title_groups/129" rel="title_group"/>
68
+ <link href="http://staging.schedule.bebanjo.net/api/titles/498" rel="title"/>
69
+ </scheduling>]
70
+
71
+
72
+ Next, explore the {API docs}[http://wiki.github.com/bebanjo/almodovar/] to learn about other resources.
50
73
 
51
74
  ==To-do
52
75
 
53
- * Ability to use parameters in linked resource calls (e.g. <tt>movida.titles(:external_id => "C51234500001")</tt>)
54
- * Memoize linked resource calls so that the same request isn't make several times
55
- * Ability to take advantage of the API _expand_ functionality (e.g. <tt>movida.titles(:expand => [:schedule, :schedulings]).schedule.schedulings</tt>)
76
+ * Memoize linked resource calls so that the same request isn't made several times
77
+ * See what is preventing latest version of Resourceful from working and fix it (Now we're using a vendorized, patched version based on resourceful 0.5.3)
56
78
 
57
- Copyright (c) 2008 BeBanjo S.L., released under the MIT license
79
+ Copyright (c) 2010 BeBanjo S.L., released under the MIT license
data/lib/almodovar.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'resourceful'
1
+ require File.dirname(__FILE__) + '/../vendor/resourceful-0.5.3-patched/lib/resourceful'
2
2
  require 'nokogiri'
3
3
 
4
4
  module Almodovar
@@ -18,19 +18,22 @@ module Almodovar
18
18
 
19
19
  private
20
20
 
21
+ undef id
22
+
21
23
  def method_missing(meth, *args, &blk)
22
- attribute = @xml.at_xpath("./*[name()='#{meth}']")
24
+ attribute = @xml.at_xpath("./*[name()='#{meth}' or name()='#{attribute_name(meth)}']")
23
25
  return node_text(attribute) if attribute
24
26
 
25
- link = @xml.at_xpath("./link[@rel='#{meth}']")
26
- return get_linked_resource(link) if link
27
+ link = @xml.at_xpath("./link[@rel='#{meth}' or @rel='#{attribute_name(meth)}']")
28
+ return get_linked_resource(link, args.first) if link
27
29
 
28
30
  super
29
31
  end
30
32
 
31
- def get_linked_resource(link)
33
+ def get_linked_resource(link, options = {})
34
+ options ||= {}
32
35
  expansion = link.at_xpath("./*")
33
- expansion ? Almodovar.instantiate(expansion, @auth) : Almodovar::Resource(link['href'], @auth)
36
+ options.empty? && expansion ? Almodovar.instantiate(expansion, @auth) : Almodovar::Resource(link['href'], @auth, options)
34
37
  end
35
38
 
36
39
  def node_text(node)
@@ -41,6 +44,10 @@ module Almodovar
41
44
  node.text
42
45
  end
43
46
  end
47
+
48
+ def attribute_name(attribute)
49
+ attribute.to_s.gsub('_', '-')
50
+ end
44
51
  end
45
52
 
46
53
  def self.Resource(url, auth, params = {})
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- version: 0.0.1
8
+ - 0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - BeBanjo S.L.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-09 00:00:00 +02:00
17
+ date: 2010-04-12 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency