gumroad-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +12 -0
- data/docs/index.md +4 -0
- data/docs/products.md +31 -0
- data/docs/sales.md +63 -0
- data/gumroad-api.gemspec +39 -0
- data/lib/gumroad/client.rb +30 -0
- data/lib/gumroad/product.rb +59 -0
- data/lib/gumroad/resource.rb +40 -0
- data/lib/gumroad/sale.rb +60 -0
- data/lib/gumroad/version.rb +7 -0
- data/lib/gumroad.rb +6 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0eeff5575149fce5619a86357619efcbbbbfe5bd8fa86c30942dd85860ad191a
|
4
|
+
data.tar.gz: 43ccb96cd7419e7d98066d8d0f4c70171c4b4e54c68eedda087644dfe4e3a4d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b63325534696aaffa9fd0cb2af7426e5c5f3ae1803a2ababa5891ddf335a797f1aa6d158eb79b4cfb5cc39cefd5a5b92cd90420b48fb0bc18dcdc7785f2f5cc
|
7
|
+
data.tar.gz: 906c311278aac8087f8e90a62cd2f7232653bf449d51ab5ded955409f39592a69e7303b0087ccc891cbeff91835b7d5fd95b4c356778fd5e687ce9c3db8901df
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/FormatString:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/StringLiteralsInInterpolation:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 120
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mehmet.beydogan@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Mehmet Beydogan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Gumroad API
|
2
|
+
|
3
|
+
This Ruby gem provides a simple interface to interact with the [Gumroad API](https://app.gumroad.com/api).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gumroad-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
Before using the Gumroad API, you must configure it with your Gumroad access token.
|
16
|
+
This token is required for authenticating your requests to the Gumroad API.
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Gumroad::Client.access_token = 'your_access_token_here'
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
products = Gumroad::Product.list
|
26
|
+
```
|
27
|
+
|
28
|
+
See the [Documentation](docs/index.md) for more details.
|
29
|
+
|
30
|
+
# Coverage
|
31
|
+
|
32
|
+
Not all endpoints are covered yet. Here is the list of what is covered and what is not:
|
33
|
+
|
34
|
+
- [x] Products
|
35
|
+
- [ ] Variant categories
|
36
|
+
- [ ] Offer codes
|
37
|
+
- [ ] Custom fields
|
38
|
+
- [ ] User
|
39
|
+
- [ ] Resource subscriptions
|
40
|
+
- [x] Sales
|
41
|
+
- [ ] Subscribers
|
42
|
+
- [ ] Licenses
|
43
|
+
|
44
|
+
You can use the unimplemented endpoints as:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Gumroad::Client.get('/products/123/subscribers')
|
48
|
+
Gumroad::Client.post('/products/123/custom_fields', body: { name: 'field_name', type: 'text' })
|
49
|
+
```
|
50
|
+
|
51
|
+
# Development
|
52
|
+
|
53
|
+
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run bundle exec rake install.
|
56
|
+
|
57
|
+
# Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
|
60
|
+
|
61
|
+
# License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of the MIT License.
|
data/Rakefile
ADDED
data/docs/index.md
ADDED
data/docs/products.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
## Products
|
2
|
+
|
3
|
+
#### Listing Products
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
products = Gumroad::Product.list
|
7
|
+
```
|
8
|
+
|
9
|
+
#### Retrieving a Product
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
product = Gumroad::Product.retrieve('product_id')
|
13
|
+
```
|
14
|
+
|
15
|
+
#### Deleting a Product
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Gumroad::Product.destroy('product_id')
|
19
|
+
```
|
20
|
+
|
21
|
+
#### Enabling a Product
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Gumroad::Product.enable('product_id')
|
25
|
+
```
|
26
|
+
|
27
|
+
#### Disabling a Product
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Gumroad::Product.disable('product_id')
|
31
|
+
```
|
data/docs/sales.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
## Sales
|
2
|
+
|
3
|
+
#### Listing Sales
|
4
|
+
|
5
|
+
It returns a tuple with the sales and the next page key for pagination.
|
6
|
+
```ruby
|
7
|
+
sales, next_page = Gumroad::Sale.list
|
8
|
+
|
9
|
+
sales.each do |sale|
|
10
|
+
sale.id # => 'sale_id'
|
11
|
+
sale.product_id # => 'product_id'
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
You can also use the filters:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
sales, next_page = Gumroad::Sale.list(product_id: 'product_id', before: '2016-01-01', after: '2015-01-01')
|
19
|
+
```
|
20
|
+
|
21
|
+
You can also use the page_key to get the next page of sales:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
sales, next_page = Gumroad::Sale.list(page_key: next_page)
|
25
|
+
```
|
26
|
+
|
27
|
+
#### Retrieving a Sale
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
sale = Gumroad::Sale.retrieve('sale_id')
|
31
|
+
|
32
|
+
sale.id # => 'sale_id'
|
33
|
+
sale.product_id # => 'product_id'
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Marking a Sale as Shipped
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
sale = Gumroad::Sale.mark_as_shipped('sale_id')
|
40
|
+
|
41
|
+
sale.success? # => true
|
42
|
+
```
|
43
|
+
or with tracking url
|
44
|
+
```ruby
|
45
|
+
sale = Gumroad::Sale.mark_as_shipped('sale_id', tracking_url: 'http://example.com/tracking')
|
46
|
+
|
47
|
+
sale.success? # => true
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Refunding a Sale
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
sale = Gumroad::Sale.refund('sale_id')
|
54
|
+
|
55
|
+
sale.success? # => true
|
56
|
+
```
|
57
|
+
or partial refund with `amount_cents`
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
sale = Gumroad::Sale.refund('sale_id', amount_cents: 1000)
|
61
|
+
|
62
|
+
sale.partially_refunded # => true
|
63
|
+
```
|
data/gumroad-api.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/gumroad/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "gumroad-api"
|
7
|
+
spec.version = Gumroad::Api::VERSION
|
8
|
+
spec.authors = ["Mehmet Beydogan"]
|
9
|
+
spec.email = ["mehmet.beydogan@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Gumroad API client"
|
12
|
+
spec.description = "A simple Ruby client for the Gumroad API."
|
13
|
+
spec.homepage = "https://github.com/beydogan/gumroad-api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/beydogan/gumroad-api"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/beydogan/gumroad-api"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(File.expand_path(f) == __FILE__) ||
|
26
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module Gumroad
|
6
|
+
# The base class for Gumroad API client.
|
7
|
+
class Client
|
8
|
+
include HTTParty
|
9
|
+
base_uri "https://api.gumroad.com/v2"
|
10
|
+
|
11
|
+
def self.access_token=(token)
|
12
|
+
default_params access_token: token
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Represents success or error message from the Gumroad API.
|
17
|
+
class Message
|
18
|
+
attr_accessor :success, :message
|
19
|
+
|
20
|
+
def initialize(attributes = {})
|
21
|
+
attributes.each do |key, value|
|
22
|
+
instance_variable_set("@#{key}", value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def success?
|
27
|
+
success
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gumroad
|
4
|
+
# Represents a Product resource from the Gumroad API.
|
5
|
+
# For more information, refer to the Gumroad API documentation on Products:
|
6
|
+
# https://gumroad.com/api#products
|
7
|
+
class Product < Resource
|
8
|
+
# Accessors for product attributes
|
9
|
+
attr_accessor :id, :name, :description, :price, :currency, :url, :thumbnail_url, :custom_fields
|
10
|
+
|
11
|
+
# Lists all products associated with the Gumroad account.
|
12
|
+
# @see https://app.gumroad.com/api#get-/products
|
13
|
+
# @return [Array<Product>] an array of Product instances.
|
14
|
+
# @return [Message] when the request fails.
|
15
|
+
def self.list
|
16
|
+
handle_resource_response get("/products")
|
17
|
+
end
|
18
|
+
|
19
|
+
# Retrieves the details of a single product by its ID.
|
20
|
+
# @see https://app.gumroad.com/api#get-/products/:id
|
21
|
+
# @param id [String] the ID of the product to retrieve.
|
22
|
+
# @return [Product] an instance of Product with the retrieved details.
|
23
|
+
# @return [Message] when the request fails.
|
24
|
+
def self.retrieve(id)
|
25
|
+
handle_resource_response get("/products/%s" % id)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Deletes a product by its ID.
|
29
|
+
# @param id [String] the ID of the product to delete.
|
30
|
+
# @return [Message] the response from the API after deleting the product.
|
31
|
+
def self.destroy(id)
|
32
|
+
handle_delete_response delete("/products/%s" % id)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Enables a product by its ID, making it available for sale.
|
36
|
+
# @param id [String] the ID of the product to enable.
|
37
|
+
# @return [Product] the updated Product instance, marked as enabled.
|
38
|
+
# @return [Message] when the request fails.
|
39
|
+
def self.enable(id)
|
40
|
+
handle_resource_response put("/products/%s/enable" % id)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Disables a product by its ID, making it unavailable for sale.
|
44
|
+
# @param id [String] the ID of the product to disable.
|
45
|
+
# @return [Product] the updated Product instance, marked as disabled.
|
46
|
+
# @return [Message] when the request fails.
|
47
|
+
def self.disable(id)
|
48
|
+
handle_resource_response put("/products/%s/disable" % id)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.convert_to_resource_object(response)
|
52
|
+
if response["products"]
|
53
|
+
response["products"].map { |product| new(product) }
|
54
|
+
else
|
55
|
+
new(response["product"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gumroad
|
4
|
+
# The base class for all Gumroad API resources.
|
5
|
+
class Resource < Client
|
6
|
+
attr_accessor :success
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
super()
|
10
|
+
|
11
|
+
attributes.each do |key, value|
|
12
|
+
self.class.send(:attr_accessor, key)
|
13
|
+
instance_variable_set("@#{key}", value)
|
14
|
+
end
|
15
|
+
|
16
|
+
@success = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def success?
|
20
|
+
success
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.handle_delete_response(response)
|
24
|
+
raise response unless response.success?
|
25
|
+
|
26
|
+
Message.new(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [anything]
|
30
|
+
def self.handle_resource_response(response)
|
31
|
+
if response.success? && response["success"]
|
32
|
+
convert_to_resource_object(response)
|
33
|
+
elsif response.success? && !response["success"]
|
34
|
+
Message.new(response)
|
35
|
+
else
|
36
|
+
raise response.response
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/gumroad/sale.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gumroad
|
4
|
+
# Represents a Sale resource from the Gumroad API.
|
5
|
+
# For more information, refer to the Gumroad API documentation on Products:
|
6
|
+
# https://gumroad.com/api#sales
|
7
|
+
class Sale < Resource
|
8
|
+
# Lists all sales associated with the Gumroad account.
|
9
|
+
# @see https://app.gumroad.com/api#get-/sales
|
10
|
+
# @param params [Hash] a hash of query parameters to filter the list of sales.
|
11
|
+
# @option params [String] :after (optional) Only return sales after this date in the form YYYY-MM-DD.
|
12
|
+
# @option params [String] :before (optional) Only return sales before this date in the form YYYY-MM-DD.
|
13
|
+
# @option params [String] :product_id (optional) Filter sales by this product ID.
|
14
|
+
# @option params [String] :email (optional) Filter sales by this email.
|
15
|
+
# @option params [String] :order_id (optional) Filter sales by this Order ID.
|
16
|
+
# @option params [String] :page_key (optional) A key representing a page of results.
|
17
|
+
# @return [Array[Array<Product>, String] an array of Sale instances and the next page key as tuple.
|
18
|
+
# @return [Message] when the request fails.
|
19
|
+
def self.list(params = {})
|
20
|
+
handle_resource_response get("/sales", query: params)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Retrieves the details of a single sale by its ID.
|
24
|
+
# @see https://app.gumroad.com/api#get-/sales/:id
|
25
|
+
# @param id [String] the ID of the sale to retrieve.
|
26
|
+
# @return [Sale] an instance of Sale with the retrieved details.
|
27
|
+
def self.retrieve(id)
|
28
|
+
handle_resource_response get("/sales/%s" % id)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Marks a sale as shipped. Available with the 'mark_sales_as_shipped' scope.
|
32
|
+
# @see https://app.gumroad.com/api#put-/sales/:id/mark_as_shipped
|
33
|
+
# @param id [String] the ID of the sale to mark as shipped.
|
34
|
+
# @param params [Hash] a hash of parameters to mark the sale as shipped.
|
35
|
+
# @option params [String] :tracking_number (optional) The tracking number for the shipment.
|
36
|
+
# @return [Sale] the updated Sale instance, marked as shipped.
|
37
|
+
def self.mark_as_shipped(id, params = {})
|
38
|
+
handle_resource_response put("/sales/%s/mark_as_shipped" % id, body: params)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Refunds a sale. Available with the 'refund_sales' scope.
|
42
|
+
# @see https://app.gumroad.com/api#put-/sales/:id/refund
|
43
|
+
# @param id [String] the ID of the sale to refund.
|
44
|
+
# @param params [Hash] a hash of parameters to refund the sale.
|
45
|
+
# @option params [String] :amount_cents (optional) The amount to refund.
|
46
|
+
# @return [Sale] the updated Sale instance, marked as refunded.
|
47
|
+
def self.refund(id, params = {})
|
48
|
+
handle_resource_response put("/sales/%s/refund" % id, body: params)
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [anything]
|
52
|
+
def self.convert_to_resource_object(response)
|
53
|
+
if response["sales"]
|
54
|
+
[response["sales"].map { |product| new(product) }, response["next_page_key"]]
|
55
|
+
else
|
56
|
+
new(response["sale"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/gumroad.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gumroad-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mehmet Beydogan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple Ruby client for the Gumroad API.
|
14
|
+
email:
|
15
|
+
- mehmet.beydogan@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- docs/index.md
|
28
|
+
- docs/products.md
|
29
|
+
- docs/sales.md
|
30
|
+
- gumroad-api.gemspec
|
31
|
+
- lib/gumroad.rb
|
32
|
+
- lib/gumroad/client.rb
|
33
|
+
- lib/gumroad/product.rb
|
34
|
+
- lib/gumroad/resource.rb
|
35
|
+
- lib/gumroad/sale.rb
|
36
|
+
- lib/gumroad/version.rb
|
37
|
+
homepage: https://github.com/beydogan/gumroad-api
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata:
|
41
|
+
homepage_uri: https://github.com/beydogan/gumroad-api
|
42
|
+
source_code_uri: https://github.com/beydogan/gumroad-api
|
43
|
+
changelog_uri: https://github.com/beydogan/gumroad-api
|
44
|
+
rubygems_mfa_required: 'true'
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.6.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.5.3
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Gumroad API client
|
64
|
+
test_files: []
|