dawanda_client 0.1.8 → 0.1.9

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.1.8
1
+ 0.1.9
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dawanda_client}
8
- s.version = "0.1.8"
8
+ s.version = "0.1.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["DaWanda GmbH"]
12
- s.date = %q{2010-03-08}
12
+ s.date = %q{2010-03-09}
13
13
  s.description = %q{Provides a friendly ruby-like interface to the Dawanda API}
14
14
  s.email = %q{api@dawanda.com}
15
15
  s.extra_rdoc_files = [
data/lib/dawanda/model.rb CHANGED
@@ -47,7 +47,8 @@ module Dawanda
47
47
  def find_all(parameter, endpoint)
48
48
  class_eval <<-CODE
49
49
  def self.find_all_by_#{parameter}(#{parameter}, params = {})
50
- response = Request.get("#{endpoint}", params)
50
+ response = Request.get("#{endpoint}", params.reject{|key, value| key == :raw_response})
51
+ return response if params[:raw_response]
51
52
  response.result.map {|listing| new(listing) }
52
53
  end
53
54
  CODE
@@ -56,7 +57,8 @@ module Dawanda
56
57
  def find_one(parameter, endpoint)
57
58
  class_eval <<-CODE
58
59
  def self.find_by_#{parameter}(#{parameter}, params = {})
59
- response = Request.get("#{endpoint}", params)
60
+ response = Request.get("#{endpoint}", params.reject{|key, value| key == :raw_response})
61
+ return response if params[:raw_response]
60
62
  new response.result
61
63
  end
62
64
  CODE
@@ -26,8 +26,6 @@ module Dawanda
26
26
  finder :all, '/colors/:hex_search/products/search'
27
27
  finder :all, '/product/:method'
28
28
 
29
-
30
-
31
29
  finder :one, '/products/:id'
32
30
 
33
31
  attribute :created, :created_at
@@ -35,7 +33,7 @@ module Dawanda
35
33
  attribute :user_id, [ :user => :id ]
36
34
 
37
35
  attributes :id, :name, :description, :created_at, :view_count, :tags,
38
- :ending, :quantity, :materials, :price, :restful_path, :product_url, :images
36
+ :ending, :quantity, :materials, :price, :restful_path, :product_url, :images, :user
39
37
 
40
38
 
41
39
  # Time that this product was created
@@ -74,7 +72,7 @@ module Dawanda
74
72
  end
75
73
 
76
74
  def shop(params = {})
77
- Shop.find_by_user_id(user_id)
75
+ Shop.find_by_user_id(user["id"])
78
76
  end
79
77
  end
80
78
  end
@@ -51,6 +51,5 @@ module Dawanda
51
51
  uri.query = query
52
52
  uri
53
53
  end
54
-
55
54
  end
56
55
  end
data/lib/dawanda.rb CHANGED
@@ -71,29 +71,29 @@ module Dawanda
71
71
  @country || 'de'
72
72
  end
73
73
 
74
- # Find a user by username. See Dawanda::User for more information.
75
- def self.user(username_or_id)
76
- User.find_by_user_id(username_or_id)
74
+ # Find a user by username. See Dawanda::User for more information.
75
+ def self.user(username_or_id, options={})
76
+ User.find_by_user_id(username_or_id, options)
77
77
  end
78
78
 
79
79
  # Find a shop by username. See Dawanda::Shop for more information.
80
- def self.shop(username_or_id)
81
- Shop.find_by_user_id(username_or_id)
80
+ def self.shop(username_or_id, options={})
81
+ Shop.find_by_user_id(username_or_id, options)
82
82
  end
83
83
 
84
84
  # Find a product by id. See Dawanda::Product for more information.
85
- def self.product(product_id)
86
- Product.find_by_id(product_id)
85
+ def self.product(product_id, options={})
86
+ Product.find_by_id(product_id, options)
87
87
  end
88
88
 
89
89
  # Find a category by id. See Dawanda::Category for more information.
90
- def self.category(category_id)
91
- Category.find_by_id(category_id)
90
+ def self.category(category_id, options={})
91
+ Category.find_by_id(category_id, options)
92
92
  end
93
93
 
94
94
  # Find a shop_category by id. See Dawanda::ShopCategory for more information.
95
- def self.shop_category(shop_category_id)
96
- ShopCategory.find_by_id(shop_category_id)
95
+ def self.shop_category(shop_category_id, options={})
96
+ ShopCategory.find_by_id(shop_category_id, options)
97
97
  end
98
98
 
99
99
  end
data/test/test_helper.rb CHANGED
@@ -3,6 +3,9 @@ $:.reject! { |e| e.include? 'TextMate' }
3
3
 
4
4
  require 'rubygems'
5
5
  require 'throat_punch'
6
+ require 'net/http'
7
+ require 'json'
8
+ require 'time'
6
9
 
7
10
  require File.dirname(__FILE__) + '/../lib/dawanda'
8
11
 
@@ -21,7 +24,7 @@ class Test::Unit::TestCase
21
24
  response = Dawanda::Response.new(stub())
22
25
 
23
26
  data = read_fixture(options[:data])
24
- data = data.first if data.size == 1
27
+ data = data.to_a.first if data.size == 1
25
28
 
26
29
  response.stubs(:result).with().returns(data)
27
30
  Dawanda::Request.stubs(:get).with(options[:for], {}).returns(response)
@@ -50,4 +53,9 @@ class Test::Unit::TestCase
50
53
  end
51
54
  end
52
55
 
56
+ def response_from_fixture(method_name)
57
+ file = File.dirname(__FILE__) + "/fixtures/#{method_name}.json"
58
+ Dawanda::Response.new(File.read(file))
59
+ end
60
+
53
61
  end
@@ -7,10 +7,9 @@ module Dawanda
7
7
 
8
8
  should "be able to find a category by :id" do
9
9
  id = 5327518
10
- response = mock_request_cycle :for => "/categories/#{id}", :data => 'getCategoryDetails'
10
+ response = mock_request_cycle({:for => "/categories/#{id}", :data => 'getCategoryDetails'})
11
11
 
12
12
  Category.expects(:new).with(response.result).returns('category')
13
-
14
13
  Category.find_by_id(id, {}).should == 'category'
15
14
  end
16
15
 
@@ -19,7 +18,7 @@ module Dawanda
19
18
  context "An instance of the Category class" do
20
19
  when_populating Category, :from => 'getCategoryDetails' do
21
20
  value_for :name, :is => '1003'
22
- value_for :product_count, :is => 754
21
+ value_for :product_count, :is => 754
23
22
  value_for :parent_id, :is => 406
24
23
  value_for :id, :is => 418
25
24
  end
@@ -31,7 +31,7 @@ module Dawanda
31
31
  user_id = 5327518
32
32
 
33
33
  product = Product.new
34
- product.expects(:user_id).returns(user_id).at_least_once
34
+ product.expects(:user).returns({"id" => user_id}).at_least_once
35
35
  response = mock_request_cycle :for => "/shops/#{user_id}", :data => 'getShopDetails'
36
36
 
37
37
  Shop.expects(:new).with(response.result).returns('shop')
@@ -1,9 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class DawandaTest < Test::Unit::TestCase
4
-
5
4
  context "The Dawanda module" do
6
-
7
5
  should "be able to set and retrieve the API key" do
8
6
  Dawanda.api_key = 'key'
9
7
  Dawanda.api_key.should == 'key'
@@ -17,38 +15,46 @@ class DawandaTest < Test::Unit::TestCase
17
15
  should "be able to find a user by username" do
18
16
  user = stub()
19
17
 
20
- Dawanda::User.expects(:find_by_user_id).with('littletjane').returns(user)
18
+ Dawanda::User.expects(:find_by_user_id).with('littletjane', {}).returns(user)
21
19
  Dawanda.user('littletjane').should == user
22
20
  end
23
21
 
22
+ should "be able to get the raw response" do
23
+ response = response_from_fixture('getUserDetails')
24
+ Dawanda::Request.expects(:get).returns(response)
25
+
26
+ user = Dawanda.user("meko", {:raw_response => true})
27
+ user.result.should_not == nil
28
+ user.pages.should_not == nil
29
+ user.entries.should_not == nil
30
+ end
31
+
24
32
  should "be able to find a shop by username" do
25
33
  shop = stub()
26
34
 
27
- Dawanda::Shop.expects(:find_by_user_id).with('littletjane').returns(shop)
35
+ Dawanda::Shop.expects(:find_by_user_id).with('littletjane', {}).returns(shop)
28
36
  Dawanda.shop('littletjane').should == shop
29
37
  end
30
38
 
31
39
  should "be able to find a product by id" do
32
40
  product = stub()
33
41
 
34
- Dawanda::Product.expects(:find_by_id).with(15).returns(product)
42
+ Dawanda::Product.expects(:find_by_id).with(15, {}).returns(product)
35
43
  Dawanda.product(15).should == product
36
44
  end
37
45
 
38
46
  should "be able to find a category by id" do
39
47
  category = stub()
40
48
 
41
- Dawanda::Category.expects(:find_by_id).with(16).returns(category)
49
+ Dawanda::Category.expects(:find_by_id).with(16, {}).returns(category)
42
50
  Dawanda.category(16).should == category
43
51
  end
44
52
 
45
53
  should "be able to find a shop category by id" do
46
54
  shop_category = stub()
47
55
 
48
- Dawanda::ShopCategory.expects(:find_by_id).with(16).returns(shop_category)
56
+ Dawanda::ShopCategory.expects(:find_by_id).with(16, {}).returns(shop_category)
49
57
  Dawanda.shop_category(16).should == shop_category
50
58
  end
51
-
52
59
  end
53
-
54
60
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 8
9
- version: 0.1.8
8
+ - 9
9
+ version: 0.1.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - DaWanda GmbH
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-08 00:00:00 +01:00
17
+ date: 2010-03-09 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20