gumrider 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "http"
4
+ gem "crack"
5
+
6
+ group :development do
7
+ gem "shoulda", ">= 0"
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.6.4"
10
+ gem "simplecov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.3.1)
5
+ git (1.2.5)
6
+ http (0.1.0)
7
+ jeweler (1.6.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ multi_json (1.0.4)
12
+ rake (0.9.2.2)
13
+ shoulda (2.11.3)
14
+ simplecov (0.5.4)
15
+ multi_json (~> 1.0.3)
16
+ simplecov-html (~> 0.5.3)
17
+ simplecov-html (0.5.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.0.0)
24
+ crack
25
+ http
26
+ jeweler (~> 1.6.4)
27
+ shoulda
28
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Vadim Demedes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "gumrider"
18
+ gem.homepage = "http://github.com/vdemedes/gumrider"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{API client for Gumroad}
21
+ gem.description = %Q{API client for Gumroad. 100% coverage of available methods}
22
+ gem.email = "sbioko@gmail.com"
23
+ gem.authors = ["Vadim Demedes"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
data/Readme.md ADDED
@@ -0,0 +1,43 @@
1
+ # Gumrider
2
+
3
+ Gumrider is an API client for Gumroad's API. 99% coverage of available methods.
4
+
5
+ # Installation
6
+
7
+ ```
8
+ gem install gumrider
9
+ ```
10
+
11
+ # Usage
12
+
13
+ ```
14
+ require 'gumrider'
15
+
16
+ client = Gumrider.new 'YOUR EMAIL', 'YOUR PASSWORD'
17
+
18
+ # Creating new link
19
+ link = client.link # like a factory method, returns Gumrider::Link instance
20
+ link.name = 'My cool PSD'
21
+ link.url = 'http://path.to.that/psd'
22
+ link.price = 4.99
23
+ link.save
24
+
25
+ # Getting link
26
+
27
+ link = client.link(link.id) # where link.id is the unique identifier
28
+ link.name # is 'My cool PSD'
29
+
30
+ # Listing links
31
+
32
+ links = client.links # array of ALL links
33
+
34
+ # Editing link
35
+
36
+ link.name = 'New name for my item!'
37
+ link.save
38
+
39
+ # Deleting link
40
+
41
+ link.delete
42
+
43
+ ```
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/gumroad.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "gumroad"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Vadim Demedes"]
12
+ s.date = "2012-02-13"
13
+ s.description = "API client for Gumroad. 100% coverage of available methods"
14
+ s.email = "sbioko@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "Rakefile",
24
+ "Readme.md",
25
+ "VERSION",
26
+ "gumroad.gemspec",
27
+ "lib/gumroad.rb",
28
+ "test/helper.rb",
29
+ "test/test_gumroad.rb"
30
+ ]
31
+ s.homepage = "http://github.com/vdemedes/ruby-gumroad"
32
+ s.licenses = ["MIT"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "1.8.10"
35
+ s.summary = "API client for Gumroad"
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<http>, [">= 0"])
42
+ s.add_runtime_dependency(%q<crack>, [">= 0"])
43
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
46
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<http>, [">= 0"])
49
+ s.add_dependency(%q<crack>, [">= 0"])
50
+ s.add_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_dependency(%q<simplecov>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<http>, [">= 0"])
57
+ s.add_dependency(%q<crack>, [">= 0"])
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
61
+ s.add_dependency(%q<simplecov>, [">= 0"])
62
+ end
63
+ end
64
+
data/lib/gumrider.rb ADDED
@@ -0,0 +1,120 @@
1
+ require 'http'
2
+ require 'crack'
3
+ require 'base64'
4
+
5
+ class Gumrider
6
+
7
+ attr_accessor :endpoint, :token
8
+
9
+ def initialize(email, password)
10
+ @email = email
11
+ @password = password
12
+ @endpoint = 'https://gumroad.com/api/v1'
13
+ end
14
+
15
+ def authenticate
16
+ response = Http.post @endpoint + '/sessions', :form => { :email => @email, :password => @password }
17
+ response = Crack::JSON.parse response
18
+ if response["success"]
19
+ @token = Base64.encode64(response["token"] + ":")
20
+ true
21
+ else
22
+ false
23
+ end
24
+ end
25
+
26
+ def link(id = false)
27
+ Gumroad::Link.new id, @token, @endpoint
28
+ end
29
+
30
+ def links
31
+ response = Http.with(:Authorization => 'Basic ' + @token).get @endpoint + '/links'
32
+ response = Crack::JSON.parse response
33
+ if response["success"]
34
+ links = []
35
+ response["links"].each do |item|
36
+ link = Gumrider::Link.new(false, @token, @endpoint)
37
+ link.name = item["name"]
38
+ link.url = item["url"]
39
+ link.price = item["price"] / 100
40
+ link.description = item["description"]
41
+ link.id = item["id"]
42
+ link.currency = item["currency"]
43
+ links.push link
44
+ end
45
+ links
46
+ else
47
+ []
48
+ end
49
+ end
50
+
51
+ class Link
52
+
53
+ attr_accessor :endpoint, :token, :id, :name, :price, :description, :url, :currency
54
+
55
+ def initialize(id, token, endpoint)
56
+ @token = token
57
+ @endpoint = endpoint
58
+ if id
59
+ response = Http.with(:Authorization => 'Basic ' + token).get endpoint + '/links/' + id
60
+ response = Crack::JSON.parse response
61
+ if response["success"]
62
+ @name = response["link"]["name"]
63
+ @url = response["link"]["url"]
64
+ @price = response["link"]["price"] / 100
65
+ @description = response["link"]["description"]
66
+ @currency = response["link"]["currency"]
67
+ @id = id
68
+ end
69
+ end
70
+ end
71
+
72
+ def save
73
+ if @id
74
+ update
75
+ else
76
+ create
77
+ end
78
+ end
79
+
80
+ def delete
81
+ response = Http.with(:Authorization => 'Basic ' + @token).delete @endpoint + '/links/' + @id
82
+ response = Crack::JSON.parse response
83
+ !!response["success"]
84
+ end
85
+
86
+ private
87
+
88
+ def create
89
+ response = Http.with(:Authorization => 'Basic ' + @token).post @endpoint + '/links', :form => {
90
+ 'link[name]' => @name,
91
+ 'link[url]' => @url,
92
+ 'link[description]' => @description,
93
+ 'link[price]' => @price * 100,
94
+ 'link[price_cents]' => @price * 100,
95
+ 'link[currency]' => @currency
96
+ }
97
+ response = Crack::JSON.parse response
98
+ if response["success"]
99
+ @id = response["link"]["id"]
100
+ true
101
+ else
102
+ false
103
+ end
104
+ end
105
+
106
+ def update
107
+ response = Http.with(:Authorization => 'Basic ' + @token).put @endpoint + '/links/' + @id, :form => {
108
+ 'link[name]' => @name,
109
+ 'link[url]' => @url,
110
+ 'link[description]' => @description,
111
+ 'link[price]' => @price * 100,
112
+ 'link[price_cents]' => @price * 100,
113
+ 'link[currency]' => @currency
114
+ }
115
+ response = Crack::JSON.parse response
116
+ !!response["success"]
117
+ end
118
+ end
119
+
120
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'gumrider'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+ $client = Gumrider.new 'EMAIL', 'PASSWORD'
4
+ $id = ''
5
+
6
+ class TestGumroad < Test::Unit::TestCase
7
+ should "authenticate" do
8
+ assert $client.authenticate
9
+ end
10
+
11
+ should "create new link" do
12
+ link = $client.link
13
+ link.name = 'Test'
14
+ link.url = 'http://example.org'
15
+ link.price = 1.79
16
+ link.save
17
+ $id = link.id
18
+ assert !!$id
19
+ end
20
+
21
+ should "list links" do
22
+ assert $client.links.size > 0
23
+ end
24
+
25
+ should "get link" do
26
+ link = $client.link($id)
27
+ assert link.name.eql? 'Nice!'
28
+ end
29
+
30
+ should "edit link" do
31
+ link = $client.link($id)
32
+ link.name = 'Nice!'
33
+ assert link.save
34
+ end
35
+
36
+ should "remove link" do
37
+ assert $client.link($id).delete
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gumrider
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vadim Demedes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: http
16
+ requirement: &70249435490960 !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: *70249435490960
25
+ - !ruby/object:Gem::Dependency
26
+ name: crack
27
+ requirement: &70249435490400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70249435490400
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &70249435489760 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70249435489760
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70249435489280 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70249435489280
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70249435488680 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70249435488680
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &70249435488120 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70249435488120
80
+ description: API client for Gumroad. 100% coverage of available methods
81
+ email: sbioko@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ files:
87
+ - .document
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE.txt
91
+ - Rakefile
92
+ - Readme.md
93
+ - VERSION
94
+ - gumroad.gemspec
95
+ - lib/gumrider.rb
96
+ - test/helper.rb
97
+ - test/test_gumrider.rb
98
+ homepage: http://github.com/vdemedes/gumrider
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: 1887047435652454777
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.10
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: API client for Gumroad
126
+ test_files: []