tagometer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .DS_Store
3
+ .bundle
4
+ pkg/*
data/CHANGELOG ADDED
@@ -0,0 +1,11 @@
1
+ 1.0.0 (11th November 2010)
2
+
3
+ * clean up release
4
+
5
+ 0.1.1 (30th December 2008)
6
+
7
+ * fixed bug where gem is looking for README.md
8
+
9
+ 0.1.0 (30th December 2008)
10
+
11
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tagometer (1.0.0)
5
+ httparty (~> 0.6.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ crack (0.1.8)
11
+ httparty (0.6.1)
12
+ crack (= 0.1.8)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ httparty (~> 0.6.1)
19
+ tagometer!
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = Tagometer
2
+
3
+ A simple wrapper for the Delicious tagometer.
4
+
5
+ == Usage:
6
+
7
+ Sample irb use (http://gist.github.com/41626):
8
+
9
+ >> require 'tagometer'
10
+ => true
11
+ >> site = Tagometer::Summary.new('http://www.mutt.org/')
12
+ => #<Tagometer::Summary:0x100034c @client=#<Tagometer::Client:0x1000310>
13
+ >> site.title
14
+ >> => "The Mutt E-Mail Client"
15
+ >> site.top_tags.keys
16
+ => ["cli", "software", "linux", "client", "tools", "mail", "unix", "mutt", "opensource", "email"]
17
+
18
+ == Requirements:
19
+
20
+ * httparty
21
+
22
+ == Install:
23
+
24
+ Install the gem:
25
+
26
+ gem install tagometer
27
+
28
+ And then load it in your project:
29
+
30
+ require 'tagometer'
31
+
32
+ == License
33
+
34
+ Copyright (c) 2010 Pete O'Grady
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining
37
+ a copy of this software and associated documentation files (the
38
+ "Software"), to deal in the Software without restriction, including
39
+ without limitation the rights to use, copy, modify, merge, publish,
40
+ distribute, sublicense, and/or sell copies of the Software, and to
41
+ permit persons to whom the Software is furnished to do so, subject to
42
+ the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/*_test.rb'
9
+ test.verbose = false
10
+ end
11
+
12
+ task :default => :test
data/lib/tagometer.rb ADDED
@@ -0,0 +1,9 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'httparty'
5
+
6
+ require 'digest/md5'
7
+ require 'tagometer/client'
8
+ require 'tagometer/summary'
9
+ require 'tagometer/version'
@@ -0,0 +1,11 @@
1
+ module Tagometer
2
+ API_URL = 'http://feeds.delicious.com/v2/json/urlinfo/'
3
+
4
+ class Client
5
+ include HTTParty
6
+
7
+ def get(md5_url)
8
+ self.class.get("#{API_URL}#{md5_url}", :format => :json)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ module Tagometer
2
+ class Summary
3
+ attr_reader :url, :client, :md5_url
4
+
5
+ def initialize(url, client=Client.new)
6
+ @url = url
7
+ @client = client
8
+ @md5_url = create_md5_url(url)
9
+ populate
10
+ end
11
+
12
+ def title
13
+ @title || ''
14
+ end
15
+
16
+ def total_posts
17
+ @total_posts || 0
18
+ end
19
+
20
+ def top_tags
21
+ @top_tags || {}
22
+ end
23
+
24
+ private
25
+
26
+ def create_md5_url(url)
27
+ Digest::MD5.hexdigest(url)
28
+ end
29
+
30
+ def populate
31
+ data = @client.get(@md5_url)
32
+
33
+ if data.any?
34
+ @title = data.first['title']
35
+ @total_posts = data.first['total_posts']
36
+ @top_tags = data.first['top_tags']
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Tagometer
2
+ VERSION = '1.0.0'
3
+ end
data/tagometer.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/tagometer/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.add_runtime_dependency("httparty", "~> 0.6.1")
6
+ s.author = "Pete O'Grady"
7
+ s.description = "A simple wrapper for the Delicious tagometer. Given a URL it returns the top tags."
8
+ s.email = "pete@peteogrady.com"
9
+ s.files = `git ls-files`.split("\n")
10
+ s.homepage = "https://github.com/peteog/tagometer"
11
+ s.name = "tagometer"
12
+ s.platform = Gem::Platform::RUBY
13
+ s.require_paths = ["lib"]
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "tagometer"
16
+ s.summary = "A simple wrapper for the Delicious tagometer"
17
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
18
+ s.version = Tagometer::VERSION
19
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ - title: Google
3
+ hash: ff90821feeb2b02a33a6f9fc8e5f3fcd
4
+ url: http://www.google.com/
5
+ total_posts: 30879
6
+ top_tags:
7
+ reference: 873
8
+ search: 9183
9
+ tools: 548
10
+ internet: 756
11
+ engine: 2106
12
+ google: 7400
13
+ research: 451
14
+ searchengines: 1112
15
+ web: 1247
16
+ searchengine: 3383
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SummaryTest < Test::Unit::TestCase
4
+ def setup
5
+ def @client.get(url)
6
+ successful_response_data
7
+ end
8
+
9
+ @summary = Tagometer::Summary.new('http://www.google.com/', @client)
10
+ end
11
+
12
+ def test_sets_client_and_url_on_initalize
13
+ assert_equal(@client, @summary.client)
14
+ assert_equal('http://www.google.com/', @summary.url)
15
+ end
16
+
17
+ def test_md5_url
18
+ assert_equal('ff90821feeb2b02a33a6f9fc8e5f3fcd', @summary.md5_url)
19
+ end
20
+
21
+ def test_title
22
+ assert_equal(successful_response_data.first['title'], @summary.title)
23
+ end
24
+
25
+ def test_total_posts
26
+ assert_equal(successful_response_data.first['total_posts'], @summary.total_posts)
27
+ end
28
+
29
+ def test_top_tags
30
+ assert_equal(successful_response_data.first['top_tags'], @summary.top_tags)
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TagometerTest < Test::Unit::TestCase
4
+ def test_version
5
+ assert_not_nil Tagometer::VERSION
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'tagometer')
3
+
4
+ def successful_response_data
5
+ load_yaml_fixture("google.yml")
6
+ end
7
+
8
+ def load_yaml_fixture(path)
9
+ absolute_path = File.join(File.dirname(__FILE__), '..', "test", "fixtures", path)
10
+ YAML::load_file absolute_path
11
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagometer
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
+ - Pete O'Grady
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-11 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: A simple wrapper for the Delicious tagometer. Given a URL it returns the top tags.
38
+ email: pete@peteogrady.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - CHANGELOG
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - README.rdoc
51
+ - Rakefile
52
+ - lib/tagometer.rb
53
+ - lib/tagometer/client.rb
54
+ - lib/tagometer/summary.rb
55
+ - lib/tagometer/version.rb
56
+ - tagometer.gemspec
57
+ - test/fixtures/google.yml
58
+ - test/summary_test.rb
59
+ - test/tagometer_test.rb
60
+ - test/test_helper.rb
61
+ has_rdoc: true
62
+ homepage: https://github.com/peteog/tagometer
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 23
85
+ segments:
86
+ - 1
87
+ - 3
88
+ - 6
89
+ version: 1.3.6
90
+ requirements: []
91
+
92
+ rubyforge_project: tagometer
93
+ rubygems_version: 1.3.7
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: A simple wrapper for the Delicious tagometer
97
+ test_files: []
98
+