dawanda_client 0.1.11 → 0.1.12
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.rdoc +25 -66
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/dawanda_client.gemspec +6 -2
- data/lib/dawanda/oauth.rb +52 -0
- data/lib/dawanda.rb +6 -1
- metadata +20 -5
data/README.rdoc
CHANGED
@@ -1,43 +1,38 @@
|
|
1
|
-
=
|
1
|
+
= DaWanda
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
The Dawanda gem provides a friendly Ruby interface to the Dawanda API
|
3
|
+
The Dawanda gem provides a friendly Ruby interface to the Dawanda API, plus a secure {OAuth}[http://wiki.github.com/dawanda/dawanda-api-client-ruby/oauth] interface to get user-specific data.
|
6
4
|
|
7
5
|
== Installation
|
8
6
|
|
9
7
|
Installing the latest stable version is simple:
|
10
8
|
|
11
|
-
|
9
|
+
sudo gem install dawanda_client
|
12
10
|
|
13
11
|
== Usage
|
14
12
|
|
15
13
|
The Dawanda API is read-only - all you need to gain access is an API Key (available
|
16
14
|
from http://dawanda.com/apps). Once you have your API key, set it in your script:
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
require 'rubygems'
|
17
|
+
require 'dawanda'
|
18
|
+
Dawanda.api_key = 'foobar'
|
19
|
+
Dawanda.country = 'de'
|
22
20
|
|
23
21
|
From there, you can make any calls to the API that you need. Note: Any call to the API can fail.
|
24
22
|
In case of an error an exception is raised. So make sure your API client codes handles it.
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
If you're starting with a user, the easiest way is to use the Dawanda.user method:
|
24
|
+
See the {wiki}[http://wiki.github.com/dawanda/dawanda-api-client-ruby/] for more information about what you can recieve via the DaWanda API.
|
29
25
|
|
30
|
-
|
31
|
-
=> #<Dawanda::User:0x141bf58 @result={"name"=>"meko", "city"=>"auma", "is_seller"=>true, ...
|
32
|
-
>> user.name
|
33
|
-
=> "meko"
|
34
|
-
>> user.id
|
35
|
-
=> 13008
|
26
|
+
== Example
|
36
27
|
|
37
|
-
|
38
|
-
for Dawanda::User.
|
28
|
+
If you're starting with a user, the easiest way is to use the Dawanda.user method:
|
39
29
|
|
40
|
-
|
30
|
+
>> user = Dawanda.get_user('meko')
|
31
|
+
=> #<Dawanda::User:0x141bf58 @result={"name"=>"meko", "city"=>"auma", "is_seller"=>true, ...
|
32
|
+
>> user.name
|
33
|
+
=> "meko"
|
34
|
+
>> user.id
|
35
|
+
=> 13008
|
41
36
|
|
42
37
|
Each user may optionally have a shop. If a user is a seller, he / she also has an
|
43
38
|
associated shop object:
|
@@ -48,50 +43,14 @@ associated shop object:
|
|
48
43
|
=> #<Dawanda::Shop:0x14170c0 @result={"is_vacation"=>false, "name"=>"MEKO STORE" ...
|
49
44
|
>> shop.name
|
50
45
|
=> "MEKO STORE"
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
>> product = shop.products.first
|
61
|
-
=> #<Dawanda::Product:0x1405f3c @result={"price"=>{"cents"=>2500, "currency_code"=>"EUR"}, "name"=>"Harmonie", ...
|
62
|
-
>> product.name
|
63
|
-
=> "Harmonie"
|
64
|
-
>> product.description
|
65
|
-
=> "Harmonie \n- Inselsymposium / Gimmlitztal \n- Eiche \n- geölt \n- L:150 / Durchmesser ca. 28cm"
|
66
|
-
>> product.product_url
|
67
|
-
=> ""http://de.dawanda.com/product/1-Harmonie""
|
68
|
-
>> product.view_count
|
69
|
-
=> 155
|
70
|
-
>> product.created_at
|
71
|
-
=> Sat Sep 16 01:35:05 +0200 2006
|
72
|
-
|
73
|
-
See the documentation for [Dawanda::Product|http://wiki.github.com/dawanda/dawanda-api/data-type-product] for more information.
|
74
|
-
|
75
|
-
|
76
|
-
== Category
|
77
|
-
|
78
|
-
Dawanda categories are organized in a tree. To get the top level of categories, you can call:
|
79
|
-
|
80
|
-
>> category = Dawanda::Category.top.first
|
81
|
-
=> #<Dawanda::Category:0x138c5d8 @result={"product_count"=>0, "name"=>"2000", "id"=>218,
|
82
|
-
>> category.parent
|
83
|
-
=> nil
|
84
|
-
>> category.children
|
85
|
-
=> [#<Dawanda::Category:0x1395cb4 @result={"product_count"=>4851, "name"=>"2001", "id"=>222, ...
|
86
|
-
>> category.product_count
|
87
|
-
=> 100
|
88
|
-
|
89
|
-
== Exception
|
90
|
-
|
91
|
-
Chances are, that for some reason a HTTP request to the dawanda API can fail. This can have many reasons, either
|
92
|
-
missing network connection or a wrong id. In case the HTTP status code is different von 2xx or 3xx an exception containing
|
93
|
-
a meaningful error message is raised.
|
94
|
-
|
46
|
+
|
47
|
+
See the {wiki}[http://wiki.github.com/dawanda/dawanda-api-client-ruby/] for more information about what you can recieve via the DaWanda API.
|
48
|
+
|
49
|
+
=== Exceptions
|
50
|
+
|
51
|
+
Chances are, that for some reason a HTTP request to the dawanda API can fail. This can have many reasons, either
|
52
|
+
missing network connection or a wrong id. In case the HTTP status code is different von 2xx or 3xx an exception containing
|
53
|
+
a meaningful error message is raised.
|
54
|
+
|
95
55
|
>> category = Dawanda::Category.find_by_id(2323)
|
96
56
|
=> RuntimeError: {"error":{"status":404,"message":"The Category 2323 could not be found"}}
|
97
|
-
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.12
|
data/dawanda_client.gemspec
CHANGED
@@ -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
|
+
s.version = "0.1.12"
|
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-
|
12
|
+
s.date = %q{2010-03-26}
|
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 = [
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/dawanda/channel.rb",
|
29
29
|
"lib/dawanda/color.rb",
|
30
30
|
"lib/dawanda/model.rb",
|
31
|
+
"lib/dawanda/oauth.rb",
|
31
32
|
"lib/dawanda/pinboard.rb",
|
32
33
|
"lib/dawanda/product.rb",
|
33
34
|
"lib/dawanda/request.rb",
|
@@ -69,9 +70,12 @@ Gem::Specification.new do |s|
|
|
69
70
|
s.specification_version = 3
|
70
71
|
|
71
72
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
73
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0.3.7.pre1"])
|
72
74
|
else
|
75
|
+
s.add_dependency(%q<oauth>, [">= 0.3.7.pre1"])
|
73
76
|
end
|
74
77
|
else
|
78
|
+
s.add_dependency(%q<oauth>, [">= 0.3.7.pre1"])
|
75
79
|
end
|
76
80
|
end
|
77
81
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Dawanda
|
2
|
+
|
3
|
+
# = OAuth
|
4
|
+
#
|
5
|
+
# Provides access to sesitive user data
|
6
|
+
|
7
|
+
class OAuth
|
8
|
+
API_PREFIX = '/api/v1/oauth'
|
9
|
+
|
10
|
+
def self.connect key, secret
|
11
|
+
@@consumer = Dawanda::OAuth.create_consumer key, secret
|
12
|
+
@@request_token = @@consumer.get_request_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.rebuild key, secret, params
|
16
|
+
@@consumer = Dawanda::OAuth.create_consumer key, secret
|
17
|
+
@@request_token = ::OAuth::RequestToken.from_hash(@@consumer, params)
|
18
|
+
@@request_token.consumer.options.merge!({:oauth_verifier => params[:oauth_verifier]})
|
19
|
+
@@access_token = @@request_token.get_access_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.authorize_url
|
23
|
+
@@request_token.authorize_url
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.access_token
|
27
|
+
@@access_token ||= nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.access_token=(access_token)
|
31
|
+
@@access_token = access_token
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get(url, options={})
|
35
|
+
Dawanda::Response.new(@@access_token.get(url).body)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.user
|
39
|
+
Dawanda::User.new(Dawanda::OAuth.get("#{API_PREFIX}/users.json").result)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def self.create_consumer key, secret
|
44
|
+
@@consumer = ::OAuth::Consumer.new(key, secret, {
|
45
|
+
:site => "http://#{Dawanda.country}.#{Dawanda.domain}",
|
46
|
+
:request_token_path => "/oauth/request_token",
|
47
|
+
:access_token_path => "/oauth/access_token",
|
48
|
+
:authorize_path => "/oauth/authorize"
|
49
|
+
})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/dawanda.rb
CHANGED
@@ -4,6 +4,9 @@ require 'net/http'
|
|
4
4
|
require 'json'
|
5
5
|
require 'time'
|
6
6
|
|
7
|
+
gem 'oauth', '>=0.3.7.pre1'
|
8
|
+
require 'oauth'
|
9
|
+
|
7
10
|
require 'dawanda/request'
|
8
11
|
require 'dawanda/response'
|
9
12
|
|
@@ -17,6 +20,8 @@ require 'dawanda/color'
|
|
17
20
|
require 'dawanda/channel'
|
18
21
|
require 'dawanda/pinboard'
|
19
22
|
|
23
|
+
require 'dawanda/oauth'
|
24
|
+
|
20
25
|
# = DaWanda Client: A friendly Ruby interface to the DaWanda API
|
21
26
|
#
|
22
27
|
# == Quick Start
|
@@ -123,4 +128,4 @@ module Dawanda
|
|
123
128
|
Pinboard.find_by_id(pinboard_id)
|
124
129
|
end
|
125
130
|
|
126
|
-
end
|
131
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 12
|
9
|
+
version: 0.1.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- DaWanda GmbH
|
@@ -14,10 +14,24 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: oauth
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 3
|
30
|
+
- 7
|
31
|
+
- pre1
|
32
|
+
version: 0.3.7.pre1
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
21
35
|
description: Provides a friendly ruby-like interface to the Dawanda API
|
22
36
|
email: api@dawanda.com
|
23
37
|
executables: []
|
@@ -39,6 +53,7 @@ files:
|
|
39
53
|
- lib/dawanda/channel.rb
|
40
54
|
- lib/dawanda/color.rb
|
41
55
|
- lib/dawanda/model.rb
|
56
|
+
- lib/dawanda/oauth.rb
|
42
57
|
- lib/dawanda/pinboard.rb
|
43
58
|
- lib/dawanda/product.rb
|
44
59
|
- lib/dawanda/request.rb
|