delicious-api-via-oauth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ See "this blog post":http://blog.floehopper.org/articles/2010/01/14/ruby-wrapper-for-the-delicious-v2-api-using-the-oauth-gem for an explanation.
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'delicious-api-via-oauth'
3
+ require 'constants'
4
+
5
+ api = Delicious::API.new(API_KEY, SHARED_SECRET)
6
+ api.posts_add!(
7
+ :url => 'http://www.google.com/',
8
+ :description => 'Testing 1 2 3',
9
+ :extended => 'Blah blah blah',
10
+ :tags => 'testing google blah'
11
+ )
@@ -0,0 +1,2 @@
1
+ require 'delicious-api-via-oauth/delicious'
2
+ require 'delicious-api-via-oauth/oauth-extensions'
@@ -0,0 +1 @@
1
+ require 'delicious-api-via-oauth/delicious/api'
@@ -0,0 +1,33 @@
1
+ module Delicious
2
+
3
+ class API
4
+
5
+ def initialize(api_key, shared_secret)
6
+ yahoo_consumer = OAuth::Yahoo::Consumer.new(api_key, shared_secret)
7
+ unless @request_token = OAuth::Yahoo::RequestToken.load
8
+ @request_token = yahoo_consumer.get_request_token
9
+ @request_token.save
10
+ end
11
+ unless @access_token = OAuth::Delicious::AccessToken.load
12
+ oauth_access_token = @request_token.get_access_token
13
+ @request_token.save
14
+ @access_token = OAuth::Delicious::AccessToken.new(oauth_access_token)
15
+ @access_token.save
16
+ end
17
+ end
18
+
19
+ def posts_add!(parameters)
20
+ response = @access_token.get('/v2/posts/add', parameters)
21
+ unless response.is_a?(Net::HTTPOK)
22
+ raise "HTTP response code: #{response.code}"
23
+ end
24
+ matches = Regexp.new('<result code="([^\"]*)" />').match(response.body)
25
+ unless matches && matches[1] == 'done'
26
+ raise "Delicious API code: '#{matches[1]}'"
27
+ end
28
+ response
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,3 @@
1
+ require 'oauth'
2
+ require 'delicious-api-via-oauth/oauth-extensions/delicious'
3
+ require 'delicious-api-via-oauth/oauth-extensions/yahoo'
@@ -0,0 +1,2 @@
1
+ require 'delicious-api-via-oauth/oauth-extensions/delicious/consumer'
2
+ require 'delicious-api-via-oauth/oauth-extensions/delicious/access_token'
@@ -0,0 +1,40 @@
1
+ module OAuth
2
+
3
+ module Delicious
4
+
5
+ class AccessToken
6
+
7
+ include OAuth::Helper
8
+
9
+ def initialize(access_token)
10
+ @access_token = access_token
11
+ consumer = @access_token.consumer
12
+ @access_token.consumer = Consumer.build(consumer.key, consumer.secret)
13
+ end
14
+
15
+ def get(path, parameters = {})
16
+ query = parameters.map { |k, v| "#{escape(k.to_s)}=#{escape(v)}" } * '&'
17
+ components = [path]
18
+ components << query unless query.empty?
19
+ url = components * '?'
20
+ @access_token.get(url)
21
+ end
22
+
23
+ def save
24
+ File.open('access_token.yml', 'w') do |file|
25
+ file.puts(self.to_yaml)
26
+ end
27
+ end
28
+
29
+ def self.load
30
+ YAML.load_file('access_token.yml')
31
+ rescue
32
+ nil
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,19 @@
1
+ module OAuth
2
+
3
+ module Delicious
4
+
5
+ SITE = 'http://api.del.icio.us'
6
+
7
+ class Consumer
8
+
9
+ def self.build(api_key, shared_secret)
10
+ OAuth::Consumer.new(api_key, shared_secret, Yahoo::PATHS.merge({
11
+ :site => SITE, :scheme => :header, :http_method => :get, :realm => 'yahooapis.com'
12
+ }))
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,2 @@
1
+ require 'delicious-api-via-oauth/oauth-extensions/yahoo/consumer'
2
+ require 'delicious-api-via-oauth/oauth-extensions/yahoo/request_token'
@@ -0,0 +1,29 @@
1
+ module OAuth
2
+
3
+ module Yahoo
4
+
5
+ PATHS = {
6
+ :request_token_path => '/oauth/v2/get_request_token',
7
+ :access_token_path => '/oauth/v2/get_token',
8
+ :authorize_path => '/oauth/v2/request_auth'
9
+ }
10
+
11
+ SITE = 'https://api.login.yahoo.com'
12
+
13
+ class Consumer
14
+
15
+ def initialize(api_key, shared_secret)
16
+ @consumer = OAuth::Consumer.new(api_key, shared_secret, PATHS.merge({
17
+ :site => SITE, :scheme => :query_string, :http_method => :get
18
+ }))
19
+ end
20
+
21
+ def get_request_token
22
+ RequestToken.new(@consumer.get_request_token)
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'yaml'
2
+
3
+ module OAuth
4
+
5
+ module Yahoo
6
+
7
+ class RequestToken
8
+
9
+ def initialize(request_token)
10
+ @request_token = request_token
11
+ end
12
+
13
+ def get_oauth_verifier
14
+ return @oauth_verifier if @oauth_verifier
15
+ `open #{@request_token.authorize_url}`
16
+ puts 'Sign-in to Yahoo in the browser to allow access to this application'
17
+ puts 'And then enter the supplied oauth_verifier :-'
18
+ @oauth_verifier = gets.chomp
19
+ end
20
+
21
+ def get_access_token
22
+ @request_token.get_access_token(:oauth_verifier => get_oauth_verifier)
23
+ end
24
+
25
+ def save
26
+ File.open('request_token.yml', 'w') do |file|
27
+ file.puts(self.to_yaml)
28
+ end
29
+ end
30
+
31
+ def self.load
32
+ YAML.load_file('request_token.yml')
33
+ rescue
34
+ nil
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: delicious-api-via-oauth
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - James Mead
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-16 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: oauth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email: james@floehopper.org
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.textile
43
+ files:
44
+ - example.rb
45
+ - README.textile
46
+ - lib/delicious-api-via-oauth/delicious/api.rb
47
+ - lib/delicious-api-via-oauth/delicious.rb
48
+ - lib/delicious-api-via-oauth/oauth-extensions/delicious/access_token.rb
49
+ - lib/delicious-api-via-oauth/oauth-extensions/delicious/consumer.rb
50
+ - lib/delicious-api-via-oauth/oauth-extensions/delicious.rb
51
+ - lib/delicious-api-via-oauth/oauth-extensions/yahoo/consumer.rb
52
+ - lib/delicious-api-via-oauth/oauth-extensions/yahoo/request_token.rb
53
+ - lib/delicious-api-via-oauth/oauth-extensions/yahoo.rb
54
+ - lib/delicious-api-via-oauth/oauth-extensions.rb
55
+ - lib/delicious-api-via-oauth.rb
56
+ has_rdoc: true
57
+ homepage: http://jamesmead.org/blog/2010-01-14-ruby-wrapper-for-the-delicious-v2-api-using-the-oauth-gem
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --main
63
+ - README.textile
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Ruby wrapper for the Delicious v2 API using the OAuth gem
91
+ test_files: []
92
+