tasty 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source :rubygems
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.1"
11
+ gem "rcov", ">= 0"
12
+ end
13
+
14
+ group :test do
15
+ gem 'mocha'
16
+ gem 'fakeweb'
17
+ end
18
+
19
+ gem 'httparty'
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.6)
5
+ fakeweb (1.2.8)
6
+ git (1.2.5)
7
+ httparty (0.5.2)
8
+ crack (= 0.1.6)
9
+ jeweler (1.5.1)
10
+ bundler (~> 1.0.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ mocha (0.9.10)
14
+ rake
15
+ rake (0.8.7)
16
+ rcov (0.8.1.2.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 1.0.0)
23
+ fakeweb
24
+ httparty
25
+ jeweler (~> 1.5.1)
26
+ mocha
27
+ rcov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 David Czarnecki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,38 @@
1
+ = tasty
2
+
3
+ Ruby gem for interacting with the del.icio.us API
4
+
5
+ * http://www.delicious.com/help/api/
6
+
7
+ == Requirements
8
+
9
+ * HTTParty
10
+ * FakeWeb (testing)
11
+ * Mocha (testing)
12
+
13
+ == Install
14
+
15
+ * sudo gem install tasty
16
+
17
+ == Example
18
+
19
+ >> require 'tasty'
20
+ => true
21
+ >> tasty = Tasty.new('delicious_username', 'delicious_password')
22
+ => #<Tasty:0x101868d80 @delicious_api_url="https://api.del.icio.us/v1/", @password="delicious_password", @username="delicious_username">
23
+
24
+ == Contributing to tasty
25
+
26
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
27
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
28
+ * Fork the project
29
+ * Start a feature/bugfix branch
30
+ * Commit and push until you are happy with your contribution
31
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
32
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2010 David Czarnecki. See LICENSE.txt for
37
+ further details.
38
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "tasty"
16
+ gem.homepage = "http://github.com/czarneckid/tasty"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby library for interacting with del.icio.us}
19
+ gem.description = %Q{Ruby library for interacting with del.icio.us}
20
+ gem.email = "czarneckid@acm.org"
21
+ gem.authors = ["David Czarnecki"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "tasty #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/lib/tasty.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'httparty'
2
+
3
+ class Tasty
4
+ include HTTParty
5
+
6
+ VERSION = '1.0.0'.freeze
7
+ DEFAULT_HEADERS = {
8
+ 'User-Agent' => "tasty gem #{VERSION}"
9
+ }
10
+
11
+ headers(DEFAULT_HEADERS)
12
+
13
+ DELICIOUS_API_URL = 'https://api.del.icio.us/v1/'
14
+
15
+ attr_accessor :delicious_api_url
16
+ attr_accessor :username
17
+ attr_accessor :password
18
+
19
+ # Initialize with your API token
20
+ def initialize(username, password, delicious_api_url = DELICIOUS_API_URL)
21
+ @username = username
22
+ @password = password
23
+ @delicious_api_url = delicious_api_url
24
+ end
25
+
26
+ def debug(location = $stderr)
27
+ self.class.debug_output(location)
28
+ end
29
+
30
+ def set_http_headers(http_headers = {})
31
+ http_headers.merge!(DEFAULT_HEADERS)
32
+ headers(http_headers)
33
+ end
34
+
35
+ # Call del.icio.us using a particular API method, api_method. The options hash is where you can add any parameters appropriate for the API call.
36
+ def get(api_method, options = {})
37
+ query = {}
38
+ query.merge!(authorization_hash)
39
+ query.merge!({:query => options})
40
+
41
+ self.class.get(@delicious_api_url + api_method, query)
42
+ end
43
+
44
+ # Post to del.icio.us using a particular API method, api_method. The parameters hash is where you add all the required parameters appropriate for the API call.
45
+ def post(api_method, options = {})
46
+ query = {}
47
+ query.merge!(authorization_hash)
48
+ query.merge!({:body => options})
49
+
50
+ self.class.post(@delicious_api_url + api_method, query)
51
+ end
52
+
53
+ private
54
+
55
+ def authorization_hash
56
+ {:basic_auth => {:username => @username, :password => @password}}
57
+ end
58
+ end
data/tasty.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tasty}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Czarnecki"]
12
+ s.date = %q{2010-12-19}
13
+ s.description = %q{Ruby library for interacting with del.icio.us}
14
+ s.email = %q{czarneckid@acm.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/tasty.rb",
28
+ "tasty.gemspec",
29
+ "test/fakeweb/delicious_posts_add_response.xml",
30
+ "test/fakeweb/delicious_posts_all_response.xml",
31
+ "test/helper.rb",
32
+ "test/test_tasty.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/czarneckid/tasty}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{Ruby library for interacting with del.icio.us}
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_tasty.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<httparty>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<httparty>, [">= 0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <result code="done" />
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <posts tag="" user="user">
3
+ <post href="http://www.weather.com/" description="weather.com"
4
+ hash="6cfedbe75f413c56b6ce79e6fa102aba" tag="weather reference"
5
+ time="2005-11-29T20:30:47Z" />
6
+ <post href="http://www.nytimes.com/"
7
+ description="The New York Times - Breaking News, World News &amp; Multimedia"
8
+ extended="requires login" hash="ca1e6357399774951eed4628d69eb84b"
9
+ tag="news media" time="2005-11-29T20:30:05Z" />
10
+ </posts>
data/test/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'tasty'
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+ require 'mocha'
3
+ require 'fakeweb'
4
+
5
+ class TestTasty < Test::Unit::TestCase
6
+ def setup
7
+ FakeWeb.allow_net_connect = false
8
+ end
9
+
10
+ def teardown
11
+ FakeWeb.allow_net_connect = true
12
+ end
13
+
14
+ def test_version_is_current
15
+ assert_equal '1.0.0', Tasty::VERSION
16
+ end
17
+
18
+ def test_can_initialize_new_tasty_class
19
+ tasty = Tasty.new('username', 'password')
20
+
21
+ assert_equal Tasty::DELICIOUS_API_URL, tasty.delicious_api_url
22
+ assert_equal 'username', tasty.username
23
+ assert_equal 'password', tasty.password
24
+ end
25
+
26
+ def test_can_set_http_headers
27
+ tasty = Tasty.new('username', 'password')
28
+ tasty.expects(:headers).at_least_once
29
+
30
+ tasty.set_http_headers({'Accept' => 'application/xml'})
31
+ end
32
+
33
+ def test_can_retrieve_all_posts
34
+ FakeWeb.register_uri(:get,
35
+ 'https://username:password@api.del.icio.us/v1/posts/all?',
36
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'delicious_posts_all_response.xml'),
37
+ :content_type => "application/xml")
38
+
39
+ tasty = Tasty.new('username', 'password')
40
+ tasty_response = tasty.get('posts/all')
41
+
42
+ assert_equal 2, tasty_response['posts']['post'].size
43
+ end
44
+
45
+ def test_can_add_post
46
+ FakeWeb.register_uri(:post,
47
+ 'https://username:password@api.del.icio.us/v1/posts/add?',
48
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'delicious_posts_add_response.xml'),
49
+ :content_type => "application/xml")
50
+
51
+ tasty = Tasty.new('username', 'password')
52
+ tasty_response = tasty.post('posts/add', :url => 'http://www.google.com', :description => 'The best search engine')
53
+
54
+ assert_equal 'done', tasty_response['result']['code']
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tasty
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - David Czarnecki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-19 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: httparty
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ prerelease: false
38
+ name: bundler
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ prerelease: false
54
+ name: jeweler
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 1
61
+ segments:
62
+ - 1
63
+ - 5
64
+ - 1
65
+ version: 1.5.1
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ prerelease: false
70
+ name: rcov
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirement: *id004
81
+ description: Ruby library for interacting with del.icio.us
82
+ email: czarneckid@acm.org
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - .document
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.rdoc
96
+ - Rakefile
97
+ - VERSION
98
+ - lib/tasty.rb
99
+ - tasty.gemspec
100
+ - test/fakeweb/delicious_posts_add_response.xml
101
+ - test/fakeweb/delicious_posts_all_response.xml
102
+ - test/helper.rb
103
+ - test/test_tasty.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/czarneckid/tasty
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.3.7
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Ruby library for interacting with del.icio.us
138
+ test_files:
139
+ - test/helper.rb
140
+ - test/test_tasty.rb