tiptaplab 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjZhYTRmYTkxN2ZmNjU0M2MwMjMwNjUxNjA3MjY3YjRkNjljNTUyZQ==
4
+ ZjI3ZjQ2MjkxYjMwNWMwMWM2MWE4ZjkyMzE3NmYzOTFmM2I2MzRkNA==
5
5
  data.tar.gz: !binary |-
6
- MWNmYjMzZGU1MGM3N2I5MjczZjZkMTlkMjU0MTE4ZjYyNWEyYmZjYg==
6
+ YjZmMmVlN2MzNWM0ODY4ZjVmODdkMjczYWQ0ZDQ0ODIwMjE1OTgzYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmJmOTZiNzkyNGNiY2ViMmRmZGVlZjQ4MDM4ZDFkOWE0YWMzOTExNzc0MjBj
10
- OTgwYTk1MWQyNzc4NTk0ZmFkZDU0NjZjYzE2Yjk5YzEwODIwMzI4Mzc4MDBj
11
- M2U4M2FiYWZlNWEyODUzMzA4NWY3YzA4YjAyYmU2MjAzOWU0Y2Q=
9
+ YTFiMGU1MWUyMjRiYTNhZjNmNjdlMGUwMWIwNzQ2NTcwNjA5YjdlNjhmNTc5
10
+ ZjM0MWUxYzI1ZTAzYzgxYzNmYTYyODUxZGY4NDYwOGY4MmZiZmU5NTM4N2U3
11
+ YTVhZmMwOWEwZDljMjRhYmI1ZThmNDc0ZjY4MTZlZDg1Mjc2MjM=
12
12
  data.tar.gz: !binary |-
13
- MGRhN2JmOTdlNmMwOTUzMTQyNWI5MDBhNjNhNzY2NzhkZDBiNzhjZmIyOWNl
14
- YzlhODIwOWMyNTEwYWNhYTA0MTU1ZWU3MTg0YzI3ZGFlYjgzMWI2MDExOGU4
15
- NmJlYjNlY2NhZjU3MTQxYTM2MzAzNjRiZGU4NmRhMWUxOTY3YWE=
13
+ YTEyN2QyYTY4ZDdhMmYyY2ZiNzNiZDQ4N2I2NjcxYWQ5NTFhOWIzYjVlOTlm
14
+ NTIzYzczZTVkNmUwMTk3NmNjZTZiNWVlMDY4ZTU3NjMyYjg0YmJhNWFkODk2
15
+ NjU0ZjMxZDBhYWYxODlmOGMyNzA0NDY2NDNhNjM5OGUxZTFjYzk=
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tiptaplab (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (3.2.11)
10
+ i18n (~> 0.6)
11
+ multi_json (~> 1.0)
12
+ diff-lcs (1.2.4)
13
+ faraday (0.8.8)
14
+ multipart-post (~> 1.2.0)
15
+ i18n (0.6.5)
16
+ multi_json (1.7.9)
17
+ multipart-post (1.2.0)
18
+ rake (10.1.0)
19
+ rspec (2.14.1)
20
+ rspec-core (~> 2.14.0)
21
+ rspec-expectations (~> 2.14.0)
22
+ rspec-mocks (~> 2.14.0)
23
+ rspec-core (2.14.5)
24
+ rspec-expectations (2.14.3)
25
+ diff-lcs (>= 1.1.3, < 2.0)
26
+ rspec-mocks (2.14.3)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ activesupport (~> 3.2.11)
33
+ bundler (~> 1.3)
34
+ faraday (~> 0.8.8)
35
+ rake
36
+ rspec (~> 2.6)
37
+ tiptaplab!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 TipTap
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Tiptaplab
2
2
 
3
- TODO: Write a gem description
3
+ Warning: This gem is unfinished, and should not be used just yet.
4
+
5
+ The tiptaplab gem will provide easy and painless access to the TipTapLab API.
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,7 +20,25 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ First, [register your application with the TipTapLab API][register]
24
+
25
+ [register]https://api.tiptap.com/oauth/applications
26
+
27
+ Then, create a new `Tiptaplab::Api` instance, specifying your `app_id` and `app_secret`:
28
+
29
+ api = Tiptaplab::Api.new(:app_id => YOUR_APP_ID, :app_secret => YOUR_APP_SECRET)
30
+
31
+ In addition to the required app_id and app_secret, you can specify `:api_environment`. If this is set to 'staging', the gem will use the [TipTapLab staging API][staging]. This is useful while your app is in development, but remember that API data created on staging will not be available once you switch to production mode, and that your App credentials may be different.
32
+
33
+ You can also make arbitrary calls to the api using the `make_call` method:
34
+
35
+ api.make_call(call_path, data, method)
36
+
37
+ The default `data` is an empty hash and the default method is 'GET', so you can make simple requests with just the call path:
38
+
39
+ api.make_call('traits')
40
+ => [{"title"=>"Susceptability", "key"=>"susceptability"}, {"title"=>"Diet", "key"=>"diet"}...
41
+
22
42
 
23
43
  ## Contributing
24
44
 
data/lib/tiptaplab.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "tiptaplab/version"
2
-
3
1
  module Tiptaplab
4
- # Your code goes here...
5
2
  end
3
+
4
+ %w(
5
+ version
6
+ api
7
+ user
8
+ brand
9
+ ).each{|m| require File.dirname(__FILE__) + '/tiptaplab/' + m }
@@ -0,0 +1,87 @@
1
+ require 'active_support/core_ext/numeric'
2
+ require 'faraday'
3
+ require 'json'
4
+
5
+ module Tiptaplab
6
+ class Api
7
+ DEFAULT_OPTIONS = {
8
+ :api_version => 3,
9
+ :api_environment => 'production'
10
+ }
11
+
12
+ def initialize *params
13
+ if params.first.is_a?(Hash)
14
+ hash_options = params.first
15
+ @api_version = hash_options[:api_version] || DEFAULT_OPTIONS[:api_version]
16
+ @api_environment = hash_options[:api_environment] || DEFAULT_OPTIONS[:api_environment]
17
+ @app_id = hash_options[:app_id]
18
+ unless @app_id
19
+ raise "No app_id specified. Please pass a Hash containing your application credentials to Tiptaplab::Api.new"
20
+ end
21
+ @app_secret = hash_options[:app_secret]
22
+ unless @app_secret
23
+ raise "No app_secret specified. Please pass a Hash containing your application credentials to Tiptaplab::Api.new"
24
+ end
25
+ else
26
+ raise "Pass init parameters as a Hash"
27
+ end
28
+ @version_str = "v#{@api_version}"
29
+ api_url = case @api_environment
30
+ when 'staging'
31
+ 'http://api.staging.tiptap.com'
32
+ else
33
+ 'https://api.tiptap.com'
34
+ end
35
+ @conn = Faraday.new(:url => api_url) do |faraday|
36
+ faraday.request :url_encoded
37
+ faraday.response :logger
38
+ faraday.adapter Faraday.default_adapter
39
+ end
40
+ end
41
+
42
+ def fetch_auth_token(opts = {})
43
+ if opts[:force] || @auth_at.nil? || (@auth_at < (opts[:cache_for]|| 60.minutes).ago)
44
+ @auth_at = Time.now
45
+ token_response = @conn.post('/oauth/token',
46
+ {
47
+ :client_id => @app_id,
48
+ :client_secret => @app_secret,
49
+ :grant_type => 'client_credentials'
50
+ }
51
+ )
52
+ if token_response.status == 200
53
+ @auth_token = JSON.parse(token_response.body)['access_token']
54
+ else
55
+ raise "Error fetching auth token. Check the log for details."
56
+ end
57
+ end
58
+ @auth_token
59
+ end
60
+
61
+ def make_call(call, data = {}, method = 'GET')
62
+ fetch_auth_token
63
+ case method
64
+ when 'GET'
65
+ response = @conn.get("/#{@version_str}/#{call}", data, {'Authorization' => "Bearer #{@auth_token}"})
66
+ if response.status == '401'
67
+ puts "Response returned unauthorized, attempting to refresh auth token"
68
+ fetch_auth_token(:force => true)
69
+ response = @conn.get("/#{@version_str}/#{call}", data, {'Authorization' => "Bearer #{@auth_token}"})
70
+ end
71
+ when 'POST'
72
+ response = @conn.post("/#{@version_str}/#{call}", data, {'Authorization' => "Bearer #{@auth_token}"})
73
+ if response.status == '401'
74
+ puts "Response returned unauthorized, attempting to refresh auth token"
75
+ fetch_auth_token(:force => true)
76
+ response = @conn.get("/#{@version_str}/#{call}", data, {'Authorization' => "Bearer #{@auth_token}"})
77
+ end
78
+ end
79
+ if (response.status/100 == 2)
80
+ JSON.parse(response.body)
81
+ else
82
+ raise "Error making request. Status: #{response.status}. Check log for details."
83
+ end
84
+ end
85
+
86
+ end
87
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ module Tiptaplab
2
+ class User
3
+ def create(params)
4
+ Tiptaplab::Api.call()
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Tiptaplab
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
Binary file
@@ -0,0 +1 @@
1
+ describe Tiptaplab
data/tiptaplab.gemspec CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.6"
24
+ spec.add_development_dependency "activesupport", "~> 3.2.11"
25
+ spec.add_development_dependency "faraday", "~> 0.8.8"
23
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiptaplab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian McLean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-23 00:00:00.000000000 Z
11
+ date: 2013-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.11
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.11
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.8
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.8
41
83
  description: TipTapLab API Integration
42
84
  email:
43
85
  - engineering@tiptap.com
@@ -45,13 +87,19 @@ executables: []
45
87
  extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
48
- - .gitignore
49
90
  - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE
50
93
  - LICENSE.txt
51
94
  - README.md
52
95
  - Rakefile
53
96
  - lib/tiptaplab.rb
97
+ - lib/tiptaplab/api.rb
98
+ - lib/tiptaplab/brand.rb
99
+ - lib/tiptaplab/user.rb
54
100
  - lib/tiptaplab/version.rb
101
+ - pkg/tiptaplab-0.0.1.gem
102
+ - spec/tiptaplab_spec.rb
55
103
  - tiptaplab.gemspec
56
104
  homepage: http://github.com/tiptapinc/tiptaplab
57
105
  licenses:
@@ -78,5 +126,6 @@ signing_key:
78
126
  specification_version: 4
79
127
  summary: Provides the ability to track and compare psychological trait information
80
128
  using the TipTapLab API.
81
- test_files: []
129
+ test_files:
130
+ - spec/tiptaplab_spec.rb
82
131
  has_rdoc:
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp