tiltify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d05abbdc1199dbe6d1b6fb133619734a3915e1d6e48825fc9f3a304b4bcc55f5
4
+ data.tar.gz: e2132fcabf47210fc09f515ae40e2b197ef9c22ee25118ba90a70bc3c3f1034a
5
+ SHA512:
6
+ metadata.gz: 04451dc33eff2f13fde623cafa8e0a1d248d10b36faf7c467f71a5dab1b93eb29cbc01a619f4981794d1017c3db79676af83e07bd1a2b637dedf7526426cae76
7
+ data.tar.gz: fe89308b9dbe265c8a0ffc87725874cb1c91d244bb79ef5b0e31c68edc8d5894b6328eccb13b7f37ed29f55ffe48d631a6aa323eff8e3b693c997497c58366e1
data/.env.example ADDED
@@ -0,0 +1 @@
1
+ TILTIFY_ACCESS_TOKEN=
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in tiltify.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "minitest", "~> 5.0"
10
+ gem "dotenv"
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tiltify (0.1.0)
5
+ faraday (~> 1.7)
6
+ faraday_middleware (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ dotenv (2.7.6)
12
+ faraday (1.8.0)
13
+ faraday-em_http (~> 1.0)
14
+ faraday-em_synchrony (~> 1.0)
15
+ faraday-excon (~> 1.1)
16
+ faraday-httpclient (~> 1.0.1)
17
+ faraday-net_http (~> 1.0)
18
+ faraday-net_http_persistent (~> 1.1)
19
+ faraday-patron (~> 1.0)
20
+ faraday-rack (~> 1.0)
21
+ multipart-post (>= 1.2, < 3)
22
+ ruby2_keywords (>= 0.0.4)
23
+ faraday-em_http (1.0.0)
24
+ faraday-em_synchrony (1.0.0)
25
+ faraday-excon (1.1.0)
26
+ faraday-httpclient (1.0.1)
27
+ faraday-net_http (1.0.1)
28
+ faraday-net_http_persistent (1.2.0)
29
+ faraday-patron (1.0.0)
30
+ faraday-rack (1.0.0)
31
+ faraday_middleware (1.2.0)
32
+ faraday (~> 1.0)
33
+ minitest (5.14.4)
34
+ multipart-post (2.1.1)
35
+ rake (13.0.6)
36
+ ruby2_keywords (0.0.5)
37
+
38
+ PLATFORMS
39
+ x86_64-linux
40
+
41
+ DEPENDENCIES
42
+ dotenv
43
+ minitest (~> 5.0)
44
+ rake (~> 13.0)
45
+ tiltify!
46
+
47
+ BUNDLED WITH
48
+ 2.2.29
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Tiltify
2
+
3
+ **This library is a work in progress**
4
+
5
+ Tiltify is a Ruby library for intereacting with the Tiltify v3 API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "tiltify"
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Set Client Details
18
+
19
+ Firstly, you'll need a Tiltify account in order to create an API Access Token. [More Info](https://tiltify.github.io/api/topics/getting-started.html)
20
+
21
+ You can get your Access Token by going here (replacing YOURUSERNAME with your username) and creating an application.
22
+
23
+ ```
24
+ https://dashboard.tiltify.com/YOURUSERNAME/my-account/connected-accounts/applications
25
+ ```
26
+
27
+ If you're not planning on using OAuth, you can set the `Redirect URLs` as `https://example.com`. Once created, copy your `Access Token` and save this:
28
+
29
+ ```ruby
30
+ @client = Tiltify::Client.new(access_token: "")
31
+ ```
32
+
33
+ The client then gives you access to each of the resources.
34
+
35
+ ## Resources
36
+
37
+ The gem maps as closely as we can to the Tiltify API so you can easily convert API examples to gem code.
38
+
39
+ Responses are created as objects like `Tiltify::Campaign`. Having types like `Tiltify::Campaign` is handy for understanding what type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
40
+
41
+ ### Campaigns
42
+
43
+ ```ruby
44
+ # Retrieves a single campaign
45
+ @client.campaigns.retrieve(campaign_id: "id")
46
+
47
+ # Retrieves the most recent donations for a campaign in descending order
48
+ @client.campaigns.donations(campaign_id: "id")
49
+
50
+ # Retrieves all rewards for a campaign
51
+ @client.campaigns.rewards(campaign_id: "id")
52
+
53
+ # Retrieves the polls and their associated options for a campaign
54
+ @client.campaigns.polls(campaign_id: "id")
55
+
56
+ # Retrieves the challenges for a campaign
57
+ @client.campaigns.challenges(campaign_id: "id")
58
+
59
+ # Retrieves the schedule for a campaign
60
+ @client.campaigns.schedule(campaign_id: "id")
61
+ ```
62
+
63
+ ### Causes
64
+
65
+ ```ruby
66
+ # Retrieves a single cause
67
+ @client.causes.retrieve(cause_id: "id")
68
+ ```
69
+
70
+ ### Users
71
+
72
+ ```ruby
73
+ # Returns details for the currently authenticated user
74
+ @client.users.me
75
+
76
+ # Retrieves a specific user by their ID or slug
77
+ @client.users.retrieve(user_id: "id")
78
+
79
+ # Retrieves a list of a users campaigns
80
+ @client.users.campaigns(user_id: "id")
81
+
82
+ # Retrieves a list of a teams a user belongs to
83
+ @client.users.teams(user_id: "id")
84
+ ```
85
+
86
+ ### Teams
87
+
88
+ ```ruby
89
+ # Retrieves a specific team by their ID or slug
90
+ @client.teams.retrieve(team_id: "id")
91
+
92
+ # Retrieves a list of a teams campaigns
93
+ @client.teams.campaigns(team_id: "id")
94
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "tiltify"
6
+
7
+ # Load environment variables from .env file
8
+ require 'dotenv/load'
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ # require "pry"
15
+ # Pry.start
16
+
17
+ @client = Tiltify::Client.new(access_token: ENV["TILTIFY_ACCESS_TOKEN"])
18
+
19
+ require "irb"
20
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+ module Tiltify
2
+ class Client
3
+ BASE_URL = "https://tiltify.com/api/v3"
4
+
5
+ attr_reader :access_token, :adapter
6
+
7
+ def initialize(access_token:, adapter: Faraday.default_adapter, stubs: nil)
8
+ @access_token = access_token
9
+ @adapter = adapter
10
+
11
+ # Test stubs for requests
12
+ @stubs = stubs
13
+ end
14
+
15
+ def campaigns
16
+ CampaignsResource.new(self)
17
+ end
18
+
19
+ def causes
20
+ CausesResource.new(self)
21
+ end
22
+
23
+ def users
24
+ UsersResource.new(self)
25
+ end
26
+
27
+ def teams
28
+ TeamsResource.new(self)
29
+ end
30
+
31
+ def connection
32
+ @connection ||= Faraday.new(BASE_URL) do |conn|
33
+ conn.request :authorization, :Bearer, access_token
34
+ conn.request :json
35
+
36
+ conn.response :dates
37
+ conn.response :json, content_type: "application/json"
38
+
39
+ conn.adapter adapter, @stubs
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ module Tiltify
2
+ class Collection
3
+ attr_reader :data, :total, :cursor
4
+
5
+ def self.from_response(response, type:)
6
+ body = response.body
7
+
8
+ new(
9
+ data: body["data"].map { |attrs| type.new(attrs) },
10
+ total: body["data"].count,
11
+ cursor: body.dig("pagination", "cursor")
12
+ )
13
+ end
14
+
15
+ def initialize(data:, total:, cursor:)
16
+ @data = data
17
+ @total = total
18
+ @cursor = cursor.nil? ? nil : cursor
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require "ostruct"
2
+
3
+ module Tiltify
4
+ class Object < OpenStruct
5
+ def initialize(attributes)
6
+ super to_ostruct(attributes)
7
+ end
8
+
9
+ def to_ostruct(obj)
10
+ if obj.is_a?(Hash)
11
+ OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
12
+ elsif obj.is_a?(Array)
13
+ obj.map { |o| to_ostruct(o) }
14
+ else # Assumed to be a primitive value
15
+ obj
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Campaign < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Cause < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Challenge < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Donation < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Poll < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Reward < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Schedule < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class Team < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Tiltify
2
+ class User < Object
3
+ end
4
+ end
@@ -0,0 +1,56 @@
1
+ module Tiltify
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response client.connection.get(url, params, headers)
13
+ end
14
+
15
+ def post_request(url, body:, headers: {})
16
+ handle_response client.connection.post(url, body, headers)
17
+ end
18
+
19
+ def patch_request(url, body:, headers: {})
20
+ handle_response client.connection.patch(url, body, headers)
21
+ end
22
+
23
+ def put_request(url, body:, headers: {})
24
+ handle_response client.connection.put(url, body, headers)
25
+ end
26
+
27
+ def delete_request(url, params: {}, headers: {})
28
+ handle_response client.connection.delete(url, params, headers)
29
+ end
30
+
31
+ def handle_response(response)
32
+ case response.status
33
+ when 400
34
+ raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
35
+ when 401
36
+ raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]}'"
37
+ when 403
38
+ raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["error"]}'"
39
+ when 404
40
+ raise Error, "Error 404: No results were found for your request. '#{response.body["error"]}'"
41
+ when 409
42
+ raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
43
+ when 429
44
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]}'"
45
+ when 500
46
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["error"]}'"
47
+ when 503
48
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["error"]}'"
49
+ when 501
50
+ raise Error, "Error 501: This resource has not been implemented. '#{response.body["error"]}'"
51
+ end
52
+
53
+ response
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,34 @@
1
+ module Tiltify
2
+ class CampaignsResource < Resource
3
+
4
+ def retrieve(campaign_id:)
5
+ Campaign.new get_request("campaigns/#{campaign_id}").body.dig("data")
6
+ end
7
+
8
+ def donations(campaign_id:, **params)
9
+ response = get_request("campaigns/#{campaign_id}/donations", params)
10
+ Collection.from_response(response, type: Donation)
11
+ end
12
+
13
+ def rewards(campaign_id:)
14
+ response = get_request("campaigns/#{campaign_id}/rewards")
15
+ Collection.from_response(response, type: Reward)
16
+ end
17
+
18
+ def polls(campaign_id:)
19
+ response = get_request("campaigns/#{campaign_id}/polls")
20
+ Collection.from_response(response, type: Poll)
21
+ end
22
+
23
+ def challenges(campaign_id:)
24
+ response = get_request("campaigns/#{campaign_id}/challenges")
25
+ Collection.from_response(response, type: Challenge)
26
+ end
27
+
28
+ def schedule(campaign_id:)
29
+ response = get_request("campaigns/#{campaign_id}/schedule")
30
+ Collection.from_response(response, type: Schedule)
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ module Tiltify
2
+ class CausesResource < Resource
3
+
4
+ def retrieve(cause_id:)
5
+ Cause.new get_request("causes/#{cause_id}").body.dig("data")
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Tiltify
2
+ class TeamsResource < Resource
3
+
4
+ def retrieve(team_id:)
5
+ Team.new get_request("teams/#{team_id}").body.dig("data")
6
+ end
7
+
8
+ def campaigns(team_id:)
9
+ response = get_request("teams/#{team_id}/campaigns")
10
+ Collection.from_response(response, type: Campaign)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ module Tiltify
2
+ class UsersResource < Resource
3
+
4
+ def me
5
+ User.new get_request("user").body.dig("data")
6
+ end
7
+
8
+ def retrieve(user_id:)
9
+ User.new get_request("users/#{user_id}").body.dig("data")
10
+ end
11
+
12
+ def campaigns(user_id:)
13
+ response = get_request("users/#{user_id}/campaigns")
14
+ Collection.from_response(response, type: Campaign)
15
+ end
16
+
17
+ def teams(user_id:)
18
+ response = get_request("users/#{user_id}/teams")
19
+ Collection.from_response(response, type: Team)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tiltify
4
+ VERSION = "0.1.0"
5
+ end
data/lib/tiltify.rb ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+
6
+ require_relative "tiltify/version"
7
+
8
+ module Tiltify
9
+
10
+ autoload :Client, "tiltify/client"
11
+ autoload :Collection, "tiltify/collection"
12
+ autoload :Error, "tiltify/error"
13
+ autoload :Resource, "tiltify/resource"
14
+ autoload :Object, "tiltify/object"
15
+
16
+ autoload :CampaignsResource, "tiltify/resources/campaigns"
17
+ autoload :CausesResource, "tiltify/resources/causes"
18
+ autoload :UsersResource, "tiltify/resources/users"
19
+ autoload :TeamsResource, "tiltify/resources/teams"
20
+
21
+ autoload :Campaign, "tiltify/objects/campaign"
22
+ autoload :Donation, "tiltify/objects/donation"
23
+ autoload :Reward, "tiltify/objects/reward"
24
+ autoload :Poll, "tiltify/objects/poll"
25
+ autoload :Challenge, "tiltify/objects/challenge"
26
+ autoload :Schedule, "tiltify/objects/schedule"
27
+ autoload :Cause, "tiltify/objects/cause"
28
+ autoload :User, "tiltify/objects/user"
29
+ autoload :Team, "tiltify/objects/team"
30
+
31
+ end
data/tiltify.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/tiltify/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "tiltify"
7
+ spec.version = Tiltify::VERSION
8
+ spec.authors = ["Dean Perry"]
9
+ spec.email = ["dean@deanpcmad.com"]
10
+
11
+ spec.summary = "A Ruby library for the Tiltify v3 API"
12
+ spec.homepage = "https://github.com/deanpcmad/tiltify"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/deanpcmad/tiltify"
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "faraday", "~> 1.7"
32
+ spec.add_dependency "faraday_middleware", "~> 1.1"
33
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiltify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dean Perry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ description:
42
+ email:
43
+ - dean@deanpcmad.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".env.example"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/tiltify.rb
56
+ - lib/tiltify/client.rb
57
+ - lib/tiltify/collection.rb
58
+ - lib/tiltify/error.rb
59
+ - lib/tiltify/object.rb
60
+ - lib/tiltify/objects/campaign.rb
61
+ - lib/tiltify/objects/cause.rb
62
+ - lib/tiltify/objects/challenge.rb
63
+ - lib/tiltify/objects/donation.rb
64
+ - lib/tiltify/objects/poll.rb
65
+ - lib/tiltify/objects/reward.rb
66
+ - lib/tiltify/objects/schedule.rb
67
+ - lib/tiltify/objects/team.rb
68
+ - lib/tiltify/objects/user.rb
69
+ - lib/tiltify/resource.rb
70
+ - lib/tiltify/resources/campaigns.rb
71
+ - lib/tiltify/resources/causes.rb
72
+ - lib/tiltify/resources/teams.rb
73
+ - lib/tiltify/resources/users.rb
74
+ - lib/tiltify/version.rb
75
+ - tiltify.gemspec
76
+ homepage: https://github.com/deanpcmad/tiltify
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://github.com/deanpcmad/tiltify
81
+ source_code_uri: https://github.com/deanpcmad/tiltify
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 2.6.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.1.6
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A Ruby library for the Tiltify v3 API
101
+ test_files: []