credits 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2247cd86b0f50d9ec9d93e8d29a7e836d6cb5ee9fb6a8578db8e87f008911b3a
4
+ data.tar.gz: 9a734a695faf979be83f306faf5f453d69e4aa5ca777a3fb1d72e202447bf8fe
5
+ SHA512:
6
+ metadata.gz: d4e4c4566af2886ab43d17853ec93d42fc729690b79e7c5d03a81f0365fc3d0c5cde7489005196a6da7413a52d5a258fd6faf3399629aea20e79a7af0e6d7ef9
7
+ data.tar.gz: 66cd3200d5a5d77c41cc36f78f8223f304c9e01b8fbff6016e20aa794bd7e28e3e628a087c7deac210fc7673e5d0ef1a55ca378ae04f8f889863bfd7a3585a66
data/exe/credits ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'credits'
5
+ Credits::CLI.start(ARGV)
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ module Credits
6
+ def self.request_remaining(token, username)
7
+ @owner = nil
8
+ @url = 'https://api.travis-ci.com/v2_subscriptions'
9
+
10
+ headers = {
11
+ 'Authorization' => "token #{token}",
12
+ 'Content-Type' => 'application/json',
13
+ 'Accept' => 'application/json',
14
+ 'Travis-API-Version' => '3',
15
+ 'path' => '/v2_subscriptions'
16
+ }
17
+ response = HTTParty.get(
18
+ @url,
19
+ query: { format: :json },
20
+ headers: headers
21
+ )
22
+
23
+ if response.code == 200
24
+ response['v2_subscriptions'].each do |sub|
25
+ if sub['owner']['@type'] == 'user' && sub['owner']['login'] == username
26
+ @owner = username
27
+ elsif sub['owner']['@type'] == 'organization' && sub['owner']['login'] == username
28
+ @owner = username
29
+ end
30
+ end
31
+ end
32
+
33
+ if response.code == 200 && !@owner.nil?
34
+ response['v2_subscriptions'].each do |sub|
35
+ if sub['owner']['@type'] == 'user' && sub['owner']['login'] == username
36
+ owner = sub['owner']['login']
37
+ remaining_credits = sub['addons'][0]['current_usage']['remaining']
38
+
39
+ print "User: #{owner}\n"
40
+ print "Remaining Travis CI Credits: #{remaining_credits}\n"
41
+ elsif sub['owner']['@type'] == 'organization' && sub['owner']['login'] == username
42
+ owner = sub['owner']['login']
43
+ remaining_credits = sub['addons'][0]['current_usage']['remaining']
44
+
45
+ print "User: #{owner}\n"
46
+ print "Remaining Travis CI Credits: #{remaining_credits}\n"
47
+ end
48
+ end
49
+ else
50
+ print 'Wrong token or username'
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Credits
4
+ VERSION = '0.1.0'
5
+ end
data/lib/credits.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'credits/version'
4
+ require 'credits/credits'
5
+ require 'thor'
6
+
7
+ module Credits
8
+ class Error < StandardError; end
9
+
10
+ class CLI < Thor
11
+ desc 'remaining [token][username]', 'Gives back remaining credits of Travis account'
12
+ def remaining(token, username)
13
+ Credits.request_remaining(token, username)
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credits
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Qasim Abdullah
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.20'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.20'
41
+ description:
42
+ email:
43
+ - qasim.abdullah@travis-ci.org
44
+ executables:
45
+ - credits
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - exe/credits
50
+ - lib/credits.rb
51
+ - lib/credits/credits.rb
52
+ - lib/credits/version.rb
53
+ homepage: https://github.com/qasim-at-tci/credits
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/qasim-at-tci/credits
58
+ source_code_uri: https://github.com/qasim-at-tci/credits
59
+ changelog_uri: https://github.com/qasim-at-tci/credits
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.0.9
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Get Travis CI remaining OSS credits on an account.
79
+ test_files: []