patterntap 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +10 -0
- data/lib/patterntap.rb +49 -0
- data/lib/patterntap/version.rb +3 -0
- data/patterntap.gemspec +19 -0
- data/test/test_patterntap.rb +22 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Mark Hayes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# PatternTap
|
2
|
+
|
3
|
+
This provides a simple wrapper for retrieving information about the latest PatternTap posts.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'patterntap'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install patterntap
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You can use the following code to access PatternTap posts in your application:
|
22
|
+
|
23
|
+
PatternTap.recent
|
24
|
+
|
25
|
+
That will return the most recent 10 posts from PatternTap. Each PatternTap post has the following methods defined on it:
|
26
|
+
|
27
|
+
* URL: The url to the post
|
28
|
+
* Title: The title of the post
|
29
|
+
* Image URL: The url to the image associated with post
|
30
|
+
* Date: The date the post was published
|
31
|
+
|
32
|
+
## Example
|
33
|
+
|
34
|
+
irb(main):002:0> post = PatternTap.recent.first
|
35
|
+
irb(main):003:0> post.title
|
36
|
+
=> "Intro Slideshow from Evernote Hello"
|
37
|
+
irb(main):004:0> post.url
|
38
|
+
=> "http://patterntap.com/pattern/intro-slideshow-evernote-hello"
|
39
|
+
irb(main):005:0> post.image_url
|
40
|
+
=> "http://patterntap.com/sites/default/files/styles/pattern-full/public/newpatterns/50327f610371b.png"
|
41
|
+
irb(main):006:0> post.date
|
42
|
+
=> 2012-08-20 11:18:08 -0700
|
data/Rakefile
ADDED
data/lib/patterntap.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "patterntap/version"
|
2
|
+
require "rss"
|
3
|
+
require "open-uri"
|
4
|
+
|
5
|
+
module PatternTap
|
6
|
+
URL = "http://patterntap.com/rss/main-tap.xml"
|
7
|
+
|
8
|
+
def self.recent
|
9
|
+
begin
|
10
|
+
rss = nil
|
11
|
+
open(URL) do |feed|
|
12
|
+
rss = RSS::Parser.parse(feed.read)
|
13
|
+
end
|
14
|
+
|
15
|
+
rss.items.map do |item|
|
16
|
+
Item.new(item)
|
17
|
+
end
|
18
|
+
rescue Exception
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Item
|
24
|
+
def initialize(item)
|
25
|
+
@item = item
|
26
|
+
end
|
27
|
+
attr_reader :item
|
28
|
+
|
29
|
+
def title
|
30
|
+
item.title
|
31
|
+
end
|
32
|
+
|
33
|
+
def image_url
|
34
|
+
# scrape screen url
|
35
|
+
img = item.description.match(/img src\=\"([^"]*)\"/)
|
36
|
+
if img
|
37
|
+
img[1]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def date
|
42
|
+
item.pubDate
|
43
|
+
end
|
44
|
+
|
45
|
+
def url
|
46
|
+
item.link
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/patterntap.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/patterntap/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mark Hayes"]
|
6
|
+
gem.email = ["mark@zurb.com"]
|
7
|
+
gem.description = %q{Access PatternTap feed}
|
8
|
+
gem.summary = %q{Access PatternTap feed}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "patterntap"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = PatternTap::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "rake"
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "patterntap"
|
3
|
+
|
4
|
+
class PatternTapTest < Test::Unit::TestCase
|
5
|
+
def test_constants
|
6
|
+
assert_equal PatternTap::URL, "http://patterntap.com/rss/main-tap.xml"
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_fetch_posts
|
10
|
+
assert_equal 10, PatternTap.recent.count
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_item_format
|
14
|
+
recent = PatternTap.recent
|
15
|
+
assert !recent.count.zero?
|
16
|
+
item = recent.first
|
17
|
+
assert item.respond_to?(:title)
|
18
|
+
assert item.respond_to?(:image_url)
|
19
|
+
assert item.respond_to?(:url)
|
20
|
+
assert item.respond_to?(:date)
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: patterntap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Hayes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Access PatternTap feed
|
31
|
+
email:
|
32
|
+
- mark@zurb.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/patterntap.rb
|
43
|
+
- lib/patterntap/version.rb
|
44
|
+
- patterntap.gemspec
|
45
|
+
- test/test_patterntap.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
hash: 3804491786810742383
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: 3804491786810742383
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.23
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Access PatternTap feed
|
76
|
+
test_files:
|
77
|
+
- test/test_patterntap.rb
|