ur-product 0.2 → 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.markdown CHANGED
@@ -21,7 +21,7 @@ API wrapper for the [Utbildningsradion](http://ur.se) product services.
21
21
  require 'ur-product'
22
22
  UR::Product.search({
23
23
  :queries => 'samtid',
24
- :filter => { :search_product_type => 'programtv' },
24
+ :filters => { :search_product_type => 'programtv' },
25
25
  :page => 1,
26
26
  :per_page => 5,
27
27
  :publicstreaming => 'NOW'
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'cucumber/rake/task'
3
+
4
+ Cucumber::Rake::Task.new do |t|
5
+ t.cucumber_opts = %w{--format pretty}
6
+ end
@@ -0,0 +1,27 @@
1
+ # language: en
2
+ Feature: UR Product
3
+ As a product
4
+ I want to be able to retrieve my data from the Metadata Cache
5
+
6
+ Scenario: Product with siblings
7
+ Given I want the product 100001
8
+ When I get the product
9
+ Then the title should be "Antarktis : En hotad kontinent"
10
+ And it should have relations
11
+ And it should have siblings
12
+ And one title in siblings should be "Antarktis : Ett vittne om framtiden"
13
+
14
+ Scenario: Invalid ID
15
+ Given I want the product 99991
16
+ When I get the product it should throw "UR::InvalidProductID"
17
+
18
+ Scenario: Multiple products
19
+ Given I want the products 100001 and 150423
20
+ When I get the products
21
+ Then the result should contain 2 products
22
+ And the second product should have the title "Vetenskapslandet"
23
+
24
+ Scenario: Check if a product has an image
25
+ Given I want the product 100001
26
+ When I get the product
27
+ Then it should have image
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ # Cucumber
3
+ require 'spec/expectations'
4
+ require 'cucumber/formatter/unicode'
5
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
6
+
7
+ # UR Product
8
+ require 'lib/ur-product'
9
+
10
+ Before do
11
+ @product = nil
12
+ @products = nil
13
+ @result = nil
14
+ end
15
+
16
+ # Given
17
+ Given /^I want the product (\d+)$/ do |id|
18
+ @id = id
19
+ end
20
+
21
+ Given /^I want the products (.+)$/ do |ids|
22
+ @ids = ids.split(' and ')
23
+ end
24
+
25
+ # When
26
+
27
+ When /^I get the product$/ do
28
+ @product = UR::Product.find(@id)
29
+ end
30
+
31
+ When /^I get the products$/ do
32
+ @products = UR::Product.find(@ids)
33
+ end
34
+
35
+ When /^I get the product it should throw "([^\"]*)"$/ do |exception|
36
+ lambda { UR::Product.find(@id) }.should raise_error(exception)
37
+ end
38
+
39
+ # Then
40
+
41
+ Then /^the title should be "(.*)"/ do |title|
42
+ @product.title.should == title
43
+ end
44
+
45
+ Then /^it should have (.*)/ do |boolean_method|
46
+ @product.send("has_#{boolean_method}?").should == true
47
+ end
48
+
49
+ Then /^one (.*) in (.*) should be "(.*)"$/ do |field, method, value|
50
+ values = []
51
+
52
+ @product.send(method).each do |product|
53
+ values << product.send(field)
54
+ end
55
+
56
+ values.include?(value).should be(true)
57
+ end
58
+
59
+ Then /^the result should contain (\d+) products$/ do |expected_size|
60
+ @products.size.should == expected_size.to_i
61
+ end
62
+
63
+ Then /^the (.+) product should have the title "([^\"]*)"$/ do |index, title|
64
+ count_translations = { 'first' => 0, 'second' => 1 }
65
+
66
+ @products[count_translations["#{index}"]].title.should == title
67
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec/expectations'
2
+
3
+ # FakeWeb
4
+ require 'fakeweb'
5
+
6
+ FakeWeb.allow_net_connect = false
7
+
8
+ faked_urls = [
9
+ 'http://metadata.ur.se/products/100001.json',
10
+ 'http://metadata.ur.se/products.json?ur_product_ids=100001,150423',
11
+ 'http://assets.ur.se/id/100001/images/1.jpg'
12
+ ]
13
+
14
+ faked_urls.each do |url|
15
+ page = `curl -is #{url}`
16
+ FakeWeb.register_uri(:get, url, :response => page)
17
+ FakeWeb.register_uri(:head, url, :response => page)
18
+ end
@@ -0,0 +1,16 @@
1
+ module UR
2
+ class Product
3
+ class DistributionEvent
4
+ attr_reader :start_date, :end_date, :platform,
5
+ :event_type, :receiving_agent_group
6
+
7
+ def initialize(data)
8
+ @start_date = Time.parse(data['startdate']) if !data['startdate'].nil?
9
+ @end_date = Time.parse(data['enddate']) if !data['enddate'].nil?
10
+ @receiving_agent_group = data['recievingagentgroup']
11
+ @platform = data['platform']
12
+ @event_type = data['type']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module UR
2
+ class Product
3
+ class Storage
4
+ attr_reader :ordernumber, :compatible, :storage_type,
5
+ :storage_format, :location, :storage_kind
6
+
7
+ def initialize(data)
8
+ @order_number = data['ordernumber']
9
+ @compatible = data['compatible']
10
+ @storage_type = data['type']
11
+ @storage_format = data['format']
12
+ @location = data['location']
13
+ @storage_kind = data['storage_kind']
14
+ end
15
+ end
16
+ end
17
+ end
data/lib/ur/product.rb CHANGED
@@ -4,21 +4,22 @@ module UR
4
4
  class Product
5
5
  # Setup
6
6
  ASSETS_URL = 'http://assets.ur.se'
7
- attr_accessor :related_products,
8
- :ur_product_id, :title, :language,
9
- :description, :easy_to_read_description,
10
- :obsoleteorderid, :status, :productionyear,
11
- :maintitle, :remainderoftitle, :producingcompany,
12
- :created, :modified, :format, :duration, :aspect_ratio,
13
- :product_type, :product_sub_type, :typical_age_range,
14
- :pubdate
7
+ attr_reader :related_products,
8
+ :ur_product_id, :title, :language,
9
+ :description, :easy_to_read_description,
10
+ :obsoleteorderid, :status, :productionyear,
11
+ :maintitle, :remainderoftitle, :producingcompany,
12
+ :created, :modified, :format, :duration, :aspect_ratio,
13
+ :product_type, :product_sub_type, :typical_age_range,
14
+ :pubdate, :storages, :distribution_events
15
15
 
16
16
  def initialize(data)
17
17
  product_data = data.include?('product') ? data['product'] : data
18
18
  relations = data.include?('relations') ? data['relations'] : []
19
19
  populate(product_data, relations)
20
20
 
21
- self.class.define_boolean_methods(['siblings'])
21
+ self.class.define_boolean_methods(['distribution_events', 'storages'])
22
+ self.class.define_relation_boolean_methods(['siblings'])
22
23
  end
23
24
 
24
25
  def self.find(id)
@@ -33,6 +34,15 @@ module UR
33
34
  end
34
35
 
35
36
  def self.define_boolean_methods(names)
37
+ names.each do |name|
38
+ define_method("has_#{name}?") do
39
+ instance_variable = instance_variable_get("@#{name}")
40
+ (!instance_variable.nil? || !instance_variable.empty?)
41
+ end
42
+ end
43
+ end
44
+
45
+ def self.define_relation_boolean_methods(names)
36
46
  names.each do |name|
37
47
  define_method("has_#{name}?") do
38
48
  related_products = instance_variable_get("@related_products")
@@ -79,9 +89,19 @@ module UR
79
89
  value = product_data[field][lang]
80
90
  end
81
91
 
82
- self.send("#{field_names.call(field)}=", value)
92
+ instance_variable_set("@#{field_names.call(field)}", value)
83
93
  end
84
94
 
95
+ # Handle the data structures
96
+ [
97
+ ['distributionevent', 'distribution_events', DistributionEvent],
98
+ ['storage', 'storages', Storage]
99
+ ].each do |name, variable, structure_class|
100
+ data = product_data[name]
101
+ instance_variable_set("@#{variable}", (!data.nil? && data.size > 0) ?
102
+ data.map { |d| structure_class.new d } : [])
103
+ end
104
+
85
105
  # Handle the relations
86
106
  if relations.size > 0
87
107
  @related_products = {}
data/lib/ur/search.rb CHANGED
@@ -6,7 +6,7 @@ module UR
6
6
  class Search
7
7
  # Setup
8
8
  SEARCH_SERVICE_URL = 'http://services.ur.se/search'
9
- attr_accessor :products, :solr, :facets
9
+ attr_reader :products, :solr, :facets
10
10
 
11
11
  def initialize(solr_params)
12
12
  solr = RSolr.connect :url => SEARCH_SERVICE_URL
data/lib/ur-product.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/ur/metadata_cache'
2
2
  require File.dirname(__FILE__) + '/ur/product'
3
+ require File.dirname(__FILE__) + '/ur/product/distribution_event.rb'
4
+ require File.dirname(__FILE__) + '/ur/product/storage.rb'
3
5
  require File.dirname(__FILE__) + '/ur/search'
4
6
 
5
7
  module UR
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- version: "0.2"
7
+ - 3
8
+ version: "0.3"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Peter Hellberg
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-04-23 00:00:00 +02:00
16
+ date: 2010-04-29 00:00:00 +02:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -82,11 +82,17 @@ extra_rdoc_files: []
82
82
 
83
83
  files:
84
84
  - README.markdown
85
+ - Rakefile
85
86
  - MIT-LICENSE
86
87
  - lib/ur-product.rb
87
88
  - lib/ur/metadata_cache.rb
88
89
  - lib/ur/product.rb
90
+ - lib/ur/product/distribution_event.rb
91
+ - lib/ur/product/storage.rb
89
92
  - lib/ur/search.rb
93
+ - features/product.feature
94
+ - features/support/env.rb
95
+ - features/step_definitions/product_steps.rb
90
96
  has_rdoc: true
91
97
  homepage: http://github.com/c7/ur-product
92
98
  licenses: