kickstapi 0.1.5 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7a27eb2fdb171795742943d1dcdf6f7dcc13856
4
- data.tar.gz: d2c7e82ac82d04e2399274f8dc5c2ad5c202e559
3
+ metadata.gz: 202f1c5ea493fcf383df3a87f710f8506aed3bd8
4
+ data.tar.gz: dcba2cf074591251e5ffaadd43500b92e034d73e
5
5
  SHA512:
6
- metadata.gz: 38c7392691d07678ade9e2400bb67a7d1c2fb1e422121f20457a774cf309f62757b510fef1e06daed6fc9230ead26ed8369f785b6ff654d433223bcb2929690c
7
- data.tar.gz: f4bb5fb43a88e151a782f99fe780e3c05ce13d4e4ac33cf29df7e166cc1b41d95ce891e41c2ad592b3fec66928311799cf2f2108676fcc06aba4f68dd2101b6a
6
+ metadata.gz: 92a015b4dd986392ea283175951073ab90369e728724b60b1089f186f3ef6e3d736d1cff7721fd10dc558a224da1dc620ba7d2ba2807f3dc6acf9ac3a90d9820
7
+ data.tar.gz: 9509895f049e5dc8ae183b2f3f84a1e4a38be60c3008c55200b6d47a4b7486ba2beb2369c1c741bca35d77b7f305047815a9b91615003ab686860ff8581d4e7a
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This gem scrapes Kickstarter to create an API that facilitates the creation of applications querying Kickstarter.
4
4
 
5
- Note that this library is not created not endorsed by Kickstarter
5
+ Note that this library is not created nor endorsed by Kickstarter
6
6
 
7
7
  ## Installation
8
8
 
@@ -47,6 +47,21 @@ project.goal # returns the fund goal
47
47
  project.end_date # returns the date that the project (will) end(s)
48
48
  project.hours_left # returns how many hours are still left on the project
49
49
 
50
+ project.rewards # returns an array of rewards
51
+ reward = project.rewards.first
52
+ reward.price # returns the price of the reward
53
+ reward.backers # returns the amount of backers on this award level
54
+ reward.description # returns the description of the award
55
+ reward.delivery_date # returns the date the reward will be delivered
56
+
57
+ # you can also fetch projects by username
58
+ projects = Kickstapi.find_projects_by_username "kristofv"
59
+ # please note that when you do this, only the name and url fields
60
+ # are filled out, in order to fill out all the other fields
61
+ # you can force a request by fetching one of the lazy loaded
62
+ # fields or explicitly calling:
63
+ projects.first.load
64
+
50
65
  ```
51
66
 
52
67
  ## Contributing
@@ -14,13 +14,13 @@ module Kickstapi
14
14
  page.search("div.project-card-wrap").each do |project|
15
15
  p = Hash.new(0)
16
16
 
17
- bb_card = project.search("h2.bbcard_name")
17
+ bb_card = project.search("h6.project-title")
18
18
  bb_card_link = bb_card.search("a").first
19
19
 
20
20
  p[:name] = bb_card_link.content
21
21
  p[:url] = "https://www.kickstarter.com#{bb_card_link.attributes["href"].value.split('?').first}"
22
22
  p[:id] = JSON.parse(project.attributes["data-project"])["id"].to_i
23
- p[:creator] = project.search(".bbcard_name span").text.gsub(/\n|by/, '')
23
+ p[:creator] = project.search("div.project-card-interior > p.mb1").text.gsub(/\n|by/, '')
24
24
 
25
25
  projects << p
26
26
  end
@@ -44,15 +44,51 @@ module Kickstapi
44
44
  project[:percentage_funded] = page.search(%Q{//div[@id='pledged']}).first.attributes['data-percent-raised'].value.to_f * 100
45
45
  project[:end_date] = DateTime.parse page.search(%Q{//span[@id='project_duration_data']}).first.attributes['data-end_time'].value
46
46
  project[:hours_left] = page.search(%Q{//span[@id='project_duration_data']}).first.attributes['data-hours-remaining'].value.to_f
47
+ project[:rewards] = parse_rewards(page.search(%Q{//ul[@id='what-you-get']}).first)
47
48
  end
48
49
  project
49
50
  end
50
51
 
52
+ def projects_by_username(username)
53
+ projects = []
54
+ source_url = "https://www.kickstarter.com/profile/#{username}"
55
+
56
+ agent.get(source_url) do |page|
57
+ page.search("a.project_item").each do |item|
58
+ project = {}
59
+
60
+ project[:name] = item.search("div.project_name").text.gsub(/\n/, '')
61
+ project[:id] = :not_loaded
62
+ project[:url] = "https://kickstarter.com#{item.attributes["href"].value}"
63
+ project[:creator] = :not_loaded
64
+
65
+ projects << project
66
+ end
67
+ end
68
+
69
+ p projects
70
+ end
71
+
51
72
  private
52
73
 
53
74
  def agent
54
75
  @agent ||= Mechanize.new
55
76
  end
56
77
 
78
+ def parse_rewards(rewards)
79
+ rewards_list = []
80
+ rewards.search("li.NS-projects-reward").each do |reward|
81
+ rewards_hash = {}
82
+
83
+ rewards_hash[:price] = reward.search("h5.mb1 > span.money").text[1..-1].gsub(/[,.]/, '').to_f
84
+ rewards_hash[:backers] = reward.search("p.backers-limits > span.backers-wrap > span.num-backers").text.to_i
85
+ rewards_hash[:description] = reward.search("div.desc > p").text
86
+ rewards_hash[:delivery_date] = DateTime.parse reward.search("div.delivery-date > time").text
87
+
88
+ rewards_list << rewards_hash
89
+ end
90
+ rewards_list
91
+ end
92
+
57
93
  end
58
94
  end
@@ -8,7 +8,8 @@ module Kickstapi
8
8
  attr_accessor :id, :name, :url, :creator
9
9
  lazy_accessor :about, :pledged, :goal,
10
10
  :currency, :percentage_funded, :backers,
11
- :status, :end_date, :hours_left
11
+ :status, :end_date, :hours_left,
12
+ :rewards
12
13
 
13
14
  def initialize(attributes = {})
14
15
  complete(attributes)
@@ -20,6 +21,13 @@ module Kickstapi
20
21
  end
21
22
  end
22
23
 
24
+ def rewards=(rewards)
25
+ @rewards = []
26
+ rewards.each do |reward|
27
+ @rewards << Kickstapi::Reward.new(reward)
28
+ end
29
+ end
30
+
23
31
  def to_s
24
32
  inspect
25
33
  end
@@ -42,6 +42,19 @@ module Kickstapi
42
42
  project
43
43
  end
44
44
 
45
+ def projects_by_username(username)
46
+ projects = []
47
+ project_hashes = @gateway.projects_by_username username
48
+ project_hashes.each do |project_hash|
49
+ project = Project.new(data_source: self)
50
+
51
+ project.complete(project_hash)
52
+
53
+ projects << project
54
+ end
55
+ projects
56
+ end
57
+
45
58
  def load(project)
46
59
  fill_project(project, @gateway.project_by_url(project.url))
47
60
  end
@@ -0,0 +1,13 @@
1
+ module Kickstapi
2
+ class Reward
3
+ attr_accessor :price, :backers, :description,
4
+ :delivery_date
5
+
6
+ def initialize(attributes={})
7
+ attributes.each do |key, value|
8
+ public_send("#{key}=", value)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Kickstapi
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/kickstapi.rb CHANGED
@@ -3,6 +3,7 @@ require "kickstapi/project"
3
3
  require "kickstapi/kickstarter_gateway"
4
4
  require "kickstapi/project_mapper"
5
5
  require "kickstapi/ghostly"
6
+ require "kickstapi/reward"
6
7
 
7
8
  require 'open-uri'
8
9
  require 'mechanize'
@@ -22,4 +23,10 @@ module Kickstapi
22
23
  mapper.project_by_url url
23
24
  end
24
25
 
26
+ def self.find_projects_by_username(username)
27
+ gw = Kickstapi::KickstarterGateway.new
28
+ mapper = Kickstapi::ProjectMapper.new(gw)
29
+
30
+ mapper.projects_by_username username
31
+ end
25
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kickstapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristof Vannotten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,7 @@ files:
100
100
  - lib/kickstapi/kickstarter_gateway.rb
101
101
  - lib/kickstapi/project.rb
102
102
  - lib/kickstapi/project_mapper.rb
103
+ - lib/kickstapi/reward.rb
103
104
  - lib/kickstapi/version.rb
104
105
  - spec/kickstapi_spec.rb
105
106
  - spec/spec_helper.rb