catchpoint 1.0.2

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.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pp'
3
+ #$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
4
+ require 'catchpoint'
5
+ c = Catchpoint.new()
6
+ pp c.get('/products')
data/lib/catchpoint.rb ADDED
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'oauth2'
4
+ require 'base64'
5
+ require 'json'
6
+
7
+ module OAuth2
8
+ class AccessToken
9
+ # Oauth2 does not base64 encode the token (which Catchpoint wants), so we do it instead:
10
+ def headers
11
+ {'Authorization' => options[:header_format] % Base64.urlsafe_encode64(token)}
12
+ end
13
+ end
14
+ end
15
+
16
+ class Catchpoint
17
+ def initialize opts={}
18
+ @key = opts["key"] || ENV['CATCHPOINT_KEY']
19
+ @secret = opts["secret"] || ENV['CATCHPOINT_SECRET']
20
+ @token_url = '/ui/api/token'
21
+ @prefix = '/ui/api/v1'
22
+ @host = 'https://io.catchpoint.com'
23
+ @version = 1
24
+ @token = nil
25
+ end
26
+
27
+ def fetch_token
28
+ client = OAuth2::Client.new(@key,@secret, site: @host, :token_url => @token_url)
29
+ @token = client.client_credentials.get_token()
30
+ end
31
+
32
+ def get endpoint,opts={}
33
+ fetch_token unless @token
34
+ res = @token.get("#{@prefix}#{endpoint}",opts)
35
+ JSON.parse(res.body)
36
+ end
37
+
38
+ def post endpoint,opts={}
39
+ fetch_token unless @token
40
+ res = @token.post("#{@prefix}#{endpoint}",opts)
41
+ JSON.parse(res.body)
42
+ end
43
+ def put endpoint,opts={}
44
+ fetch_token unless @token
45
+ res = @token.put("#{@prefix}#{endpoint}",opts)
46
+ JSON.parse(res.body)
47
+ end
48
+ def delete endpoint,opts={}
49
+ fetch_token unless @token
50
+ res = @token.delete("#{@prefix}#{endpoint}",opts)
51
+ JSON.parse(res.body)
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catchpoint
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Nicklay
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth2
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Wrapper and CLI for Catchpoint API
31
+ email: david-vv@nicklay.com
32
+ executables:
33
+ - catchpoint-list-products
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/catchpoint.rb
38
+ - bin/catchpoint-list-products
39
+ homepage: https://github.com/venturaville/catchpoint-api
40
+ licenses:
41
+ - MIT
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.23
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Catchpoint API wrapper and CLI
64
+ test_files: []
65
+ has_rdoc: