claire_client 0.0.3 → 0.0.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{claire_client}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matheus E. Muller"]
12
- s.date = %q{2010-04-28}
12
+ s.date = %q{2010-05-01}
13
13
  s.description = %q{This gem is a Ruby client for the St. Claire Media Server, which power power Canção Nova's reach of video and streamming web services.}
14
14
  s.email = %q{hello@memuller.com}
15
15
  s.extra_rdoc_files = [
data/lib/claire_client.rb CHANGED
@@ -15,7 +15,7 @@ end
15
15
  #main module here.
16
16
  module Claire
17
17
  module Client
18
- %w(rubygems open-uri active_support hashie).each { |lib| require lib }
18
+ %w(rubygems active_support hashie).each { |lib| require lib }
19
19
  @@hostname = "localhost:3000"
20
20
  @@api_key = "33c80d2e38e6b1753982500721f76eccaee0d111"
21
21
  @@format = 'xml'
@@ -41,13 +41,14 @@ module Claire
41
41
 
42
42
  # assembles an URL from an string of params.
43
43
  def self.assemble_url url="", params={}
44
- url = "http://#{@@hostname}/#{url}"
44
+ url = "http://#{@@hostname}/#{url}"
45
45
  url += ".#{@@format.downcase}" if @@format
46
46
  uri = URI.parse url
47
47
  (uri.query ||= "") << "api_key=#{@@api_key}"
48
48
  params.each do |k,v|
49
49
  uri.query << "&#{k}=#{v}"
50
50
  end
51
+ puts uri
51
52
  uri
52
53
 
53
54
  end
@@ -55,12 +56,9 @@ module Claire
55
56
  # gets an URL. Assembles it first.
56
57
  def self.get url=''
57
58
  url = assemble_url(url)
58
- request = open(url)
59
- return request.read if request.status.first.to_i == 200
60
- nil
61
- rescue Exception => e
62
-
63
-
59
+ request = Net::HTTP.get_response url
60
+ return request.body if request.is_a? Net::HTTPSuccess
61
+ rescue Exception => e
64
62
  raise
65
63
  end
66
64
 
@@ -6,8 +6,7 @@ module Claire
6
6
  attr_reader :body, :document
7
7
 
8
8
  # gets, parses, and builds objects.
9
- def initialize(arg)
10
- #puts Claire::Client.respond_to? :get
9
+ def initialize(arg, klass=nil)
11
10
  @body = Claire::Client.get(arg)
12
11
  @document = Hashie::Mash.new(Hashie::Mash.from_xml(@body))
13
12
  @document = @document.rss if @document.rss
@@ -19,6 +18,7 @@ module Claire
19
18
  else
20
19
  @items = [@document.item]
21
20
  end
21
+ @klass = klass
22
22
  build_items
23
23
  end
24
24
 
@@ -42,7 +42,11 @@ module Claire
42
42
  then item.link
43
43
  else item.link.first
44
44
  end
45
- klass = ("Claire::Client::" + link.split('/')[-2].classify).constantize
45
+ if @klass
46
+ klass = @klass.is_a?(String) ? @klass.constantize : @klass
47
+ else
48
+ klass = ("Claire::Client::" + link.split('/')[-2].classify).constantize
49
+ end
46
50
  obj = klass.new(item)
47
51
  (@objects||=[]) << obj
48
52
 
@@ -8,7 +8,7 @@ module Claire
8
8
  # if passed a block, gets the list, them applies a local
9
9
  # filter to the received items, returning an Array.
10
10
  def all &block
11
- list = List.new(self.base_url)
11
+ list = List.new(self.base_url, self)
12
12
  return list unless block
13
13
  items = []
14
14
  list.each do |item|
@@ -30,6 +30,11 @@ describe Claire::Client::Listable do
30
30
  it "should return a Claire::List on the item's base URL" do
31
31
  Video.all.should be_a_kind_of Claire::Client::List
32
32
  end
33
+
34
+ it "should be able to specify the class of the resulting listed items" do
35
+ Video.all.each{ |v| v.should_not be_a_kind_of Claire::Client::Video }
36
+ Video.all.each{ |v| v.should be_a_kind_of Video }
37
+ end
33
38
  end
34
39
 
35
40
  it "delegate a count property to its all method" # do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matheus E. Muller
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-28 00:00:00 -03:00
17
+ date: 2010-05-01 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency