instapi 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
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ instapi
2
+ ====
3
+
4
+ Wrapper of the Instapaper Simple API. Instaピ!
5
+
6
+ Feature
7
+ ----
8
+
9
+ * get unread bookmarks
10
+ * archive a bookmark
11
+ * delete a bookmark
12
+ * get a content of bookmark as text
13
+
14
+ Install
15
+ ----
16
+
17
+ gem install instapi
18
+
19
+ Example
20
+ ----
21
+
22
+ require 'instapi'
23
+
24
+ i = Instapi.new('username', 'password')
25
+ i.unread.each do |bookmark|
26
+ p bookmark
27
+ end
28
+
29
+ Copyright
30
+ ----
31
+
32
+ Copyright (c) 2012 jugyo, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ require 'instapi'
2
+
3
+ # i = Instapi.new('username', 'password')
4
+ i = Instapi.new(*ARGV)
5
+ i.add('https://github.com/jugyo')
@@ -0,0 +1,7 @@
1
+ require 'instapi'
2
+
3
+ # i = Instapi.new('username', 'password')
4
+ i = Instapi.new(*ARGV)
5
+ i.unread.each do |bookmark|
6
+ p bookmark
7
+ end
data/instapi.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "instapi/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "instapi"
7
+ s.version = Instapi::VERSION
8
+ s.authors = ["jugyo"]
9
+ s.email = ["jugyo.org@gmail.com"]
10
+ s.homepage = "https://github.com/jugyo/instapi"
11
+ s.summary = %q{Wrapper of the Instapaper Simple API. Instaピ!}
12
+ s.description = %q{Wrapper of the Instapaper Simple API. Instaピ!}
13
+
14
+ s.rubyforge_project = "instapi"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "httpclient"
22
+ s.add_runtime_dependency "nokogiri"
23
+ end
@@ -0,0 +1,3 @@
1
+ module Instapi
2
+ VERSION = "1.0.0"
3
+ end
data/lib/instapi.rb ADDED
@@ -0,0 +1,47 @@
1
+ require 'httpclient'
2
+ require 'nokogiri'
3
+
4
+ class Instapi
5
+ BASE_URL = "https://www.instapaper.com"
6
+
7
+ attr_reader :username, :password
8
+
9
+ def initialize(username, password)
10
+ @username, @password = username, password
11
+ end
12
+
13
+ def client
14
+ return @client if @client
15
+ @client = HTTPClient.new
16
+ @client.post("#{BASE_URL}/user/login", :username => username, :password => password)
17
+ @client
18
+ end
19
+
20
+ def add(url, options = {})
21
+ get('/api/add', {:url => url, :username => username, :password => password}.merge(options))
22
+ end
23
+
24
+ def unread
25
+ Nokogiri::HTML(get("/u")).css('.tableViewCell').map do |elem|
26
+ id = elem[:id].scan(/tableViewCell(\d+)/)[0][0]
27
+ link = elem.css('.tableViewCellTitleLink').first
28
+ {:id => id, :title => link.text, :url => link[:href]}
29
+ end
30
+ end
31
+
32
+ def archive(id)
33
+ get("/skip/#{id}")
34
+ end
35
+
36
+ def delete(id)
37
+ get("/delete/#{id}")
38
+ end
39
+
40
+ def text(url)
41
+ Nokogiri::HTML(get("/text?u=#{url}")).css('#story').text
42
+ end
43
+
44
+ def get(path, params = {})
45
+ client.get_content(BASE_URL + path, params)
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instapi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - jugyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-01-21 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httpclient
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: nokogiri
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ description: "Wrapper of the Instapaper Simple API. Insta\xE3\x83\x94!"
38
+ email:
39
+ - jugyo.org@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - examples/bookmark.rb
52
+ - examples/get_unread.rb
53
+ - instapi.gemspec
54
+ - lib/instapi.rb
55
+ - lib/instapi/version.rb
56
+ homepage: https://github.com/jugyo/instapi
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project: instapi
79
+ rubygems_version: 1.8.10
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: "Wrapper of the Instapaper Simple API. Insta\xE3\x83\x94!"
83
+ test_files: []
84
+