kickstapi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTZmZTAxNDgwYzIxMTJkNmQwZWQ1MTUwOTFhOTFjM2RjNmViNWRlZQ==
5
+ data.tar.gz: !binary |-
6
+ MGQxZjk0MTA0ZjZhOTRjM2M0N2ZhYmE1ZTFlZDU3YTIzZTg4MTI2NA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDkwNzllMmNhOTM1ZGExMWMxN2NmOThiMGViZTExMTkwMGY4NzZjNzgwYzZm
10
+ ZTQxNGE0Y2ZkYTZhMTlmZmEwMjdkMjNjZmVhZTAwMDE2ZTE1ODhjZjIyM2M3
11
+ MThjZGQ0Y2M5ZWU3ZTIzMmM5NmEzMWE1YWVhOWU0Mjk2NzEzY2M=
12
+ data.tar.gz: !binary |-
13
+ NWZhMTU3MWU4MzNhYjEwYjIwZTZiZDFjMDg1MGEwMWM3NDdkOWMyMTMxZGQ0
14
+ MmRiNzcyMTFkN2U1NWMwNmExODdhM2IzY2QzMTllMjY1MzE1YzRhZTU1YmVj
15
+ MTRkM2UyOGQxMDZlZDkyZGRlNTBhMWU1NmJhNzg4Y2EyODhkNGM=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kickstapi.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kristof Vannotten
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,50 @@
1
+ # Kickstapi [![Build Status](https://travis-ci.org/kvannotten/kickstapi.png?branch=master)](https://travis-ci.org/kvannotten/kickstapi)
2
+
3
+ This gem scrapes Kickstarter to create an API that facilitates the creation of applications querying Kickstarter.
4
+
5
+ Note that this library is not created not endorsed by Kickstarter
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'kickstapi'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kickstapi
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'kickstapi'
25
+
26
+ # this gives you an array of Project objects containing 'Planetary Annihilation'
27
+ projects = Kickstapi.search_projects "Planetary Annihilation"
28
+
29
+ # lets take the first project
30
+ project = projects.first
31
+
32
+ # we can then perform the following methods on it
33
+ project.name
34
+ project.url
35
+ project.about
36
+ project.creator
37
+ project.pledged
38
+ project.percentage_funded
39
+ project.backers
40
+ project.status
41
+
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/kickstapi.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kickstapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kickstapi"
8
+ spec.version = Kickstapi::VERSION
9
+ spec.authors = ["Kristof Vannotten"]
10
+ spec.email = ["kristof@vannotten.be"]
11
+ spec.description = %q{Ruby gem that offers an API for kickstarter}
12
+ spec.summary = %q{This gem offers an API for Kickstarter}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "simplecov"
25
+
26
+ ["mechanize"].each do |gem_name|
27
+ spec.add_dependency gem_name
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Kickstapi
2
+ class Project
3
+ attr_accessor :name, :url, :creator, :about, :pledged, :percentage_funded, :backers, :status
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Kickstapi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/kickstapi.rb ADDED
@@ -0,0 +1,44 @@
1
+ require "kickstapi/version"
2
+ require "kickstapi/project"
3
+
4
+ require 'open-uri'
5
+ require 'mechanize'
6
+
7
+ module Kickstapi
8
+ def self.get_agent
9
+ @agent ||= Mechanize.new
10
+ end
11
+
12
+ def self.search_projects filter = ""
13
+ search_url = "http://www.kickstarter.com/projects/search?utf8=%E2%9C%93&term=#{URI::encode filter}"
14
+
15
+ projects = []
16
+ Kickstapi.get_agent.get(search_url) do |page|
17
+ page.search("div.project-card").each do |project|
18
+ p = Project.new
19
+ bb_card = project.search("h2.bbcard_name")
20
+ bb_card_link = bb_card.search("a").first
21
+
22
+ p.name = bb_card_link.content
23
+ p.url = bb_card_link.attributes["href"].value
24
+
25
+ bb_card_author = bb_card.search("span").first
26
+ p.creator = bb_card_author.content.gsub(/\nby\n/, '').gsub(/\n/, '')
27
+ p.about = project.search("p.bbcard_blurb").first.content.strip
28
+
29
+ if project.search(".project-failed").first.nil? then
30
+ p.pledged = project.search("strong.project-pledged-amount").first.content.gsub(/\n/, '').gsub(/pledged/, '')
31
+ p.percentage_funded = project.search("strong.project-pledged-percent").first.content.gsub(/\n/, '').gsub(/funded/, '')
32
+ p.backers = project.search("li.middle").first.search("strong").first.content.gsub(/\n/, '')
33
+ p.status = project.search("li.last").first.search("strong").first.content
34
+ else
35
+ p.status = "Failed"
36
+ end
37
+ projects << p
38
+ end
39
+ end
40
+
41
+ projects
42
+ end
43
+
44
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kickstapi do
4
+ it 'should have a version number' do
5
+ Kickstapi::VERSION.should_not be_nil
6
+ end
7
+
8
+ before :all do
9
+ @projects = Kickstapi.search_projects "Planetary Annihilation" # succesful project
10
+ @failures = Kickstapi.search_projects "Quala" # failing project
11
+ end
12
+
13
+ context 'projects' do
14
+ subject { @projects }
15
+
16
+ it { should be_an_instance_of Array }
17
+
18
+ it { should_not be_empty }
19
+ end
20
+
21
+ context 'a project' do
22
+ subject { @projects.first }
23
+
24
+ [:name, :url, :creator, :about, :pledged, :percentage_funded, :backers, :status].each do |method|
25
+ it { should respond_to method }
26
+ its(method) { should_not be_empty }
27
+ end
28
+ end
29
+
30
+ context 'failed project' do
31
+ subject { @failures.first }
32
+
33
+ its(:status) { should eql "Failed" }
34
+ [:pledged, :percentage_funded, :backers].each do |method|
35
+ its(method) { should be_nil }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
+ require 'kickstapi'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kickstapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kristof Vannotten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mechanize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby gem that offers an API for kickstarter
84
+ email:
85
+ - kristof@vannotten.be
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - kickstapi.gemspec
98
+ - lib/kickstapi.rb
99
+ - lib/kickstapi/project.rb
100
+ - lib/kickstapi/version.rb
101
+ - spec/kickstapi_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.5
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: This gem offers an API for Kickstarter
127
+ test_files:
128
+ - spec/kickstapi_spec.rb
129
+ - spec/spec_helper.rb