viggles 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjFkZTRlYTJiYWNmZDU5OTgxM2M3ZDY4NTYzY2U4ZDI4NDY2MzBhNw==
5
+ data.tar.gz: !binary |-
6
+ MTJiYjgwZmFlOTkxNTg5MzZlZTI4NWFiNDgzYzk2OTlhMjZhZWMxYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NDI4MjI5ZGJkMGI0N2UyOTQ5YzhmYTJmM2QyZDM4OTlmNTEwN2E4NDU2YjFl
10
+ ZDQ5Zjc5OWRlM2QxZDdhMmY4YjExN2Y4YjllMWRlZDBlNzRiODEyZmNjYWE2
11
+ ZWU4NDI1NTgwZjkwMTBmOWQwMTM5ODQ2NjA3YzE5MTQwMDk2MzQ=
12
+ data.tar.gz: !binary |-
13
+ ZTM1YmEyN2U3NmI5ZTJhMjhhZGNiMTAzMGQ2MmQ2NmY4MDI1OWIxYjAxMDk1
14
+ OGZiMzBlYWUxM2ExYzAyNjQ0Njc5NjUyNmU2YjY5MWZkYmYyODI5YTY0MmQ0
15
+ NzFkNjFhMDQxNDhjYzY1ZmI0ZjdmMzk0NWQyMDQ2NDE0ZDAzNDA=
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers 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. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in viggles.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sathya Sekaran
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.
@@ -0,0 +1,37 @@
1
+ # Viggles
2
+
3
+ Viggles is a ruby gem which helps you deposit/withdraw Viggle points, and register/update Viggle users.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'viggles'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install viggles
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/viggles/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "viggles"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,142 @@
1
+ require "rest_client"
2
+ require "viggles/version"
3
+ require "openssl"
4
+ require "base64"
5
+
6
+ module Viggles
7
+
8
+ class Api
9
+
10
+ def initialize(params = {})
11
+ @key = params[:key]
12
+ @token = params[:token]
13
+ @secret = params[:secret]
14
+ @api = RestClient::Resource.new('https://sapi-stage.choosedigital.com')
15
+ # @api = RestClient::Resource.new('http://requestb.in/1a8yhns1')
16
+ end
17
+
18
+ def token
19
+ response = @api['token'].get headers
20
+ # result = @api.get headers # for the requestb.in endpoint for testing
21
+ JSON.parse(response).tap do |data|
22
+ if data['success'] == true
23
+ @token = data['token']
24
+ end
25
+ end
26
+ end
27
+
28
+ ##
29
+ # User Endpoints
30
+ ##
31
+
32
+ def register(viggle_member_id)
33
+ params = {
34
+ token: @token,
35
+ viggleMemberId: viggle_member_id,
36
+ authentication: auth(@token + viggle_member_id)
37
+ }
38
+
39
+ begin
40
+ response = @api['register'].post params.to_json, headers
41
+ rescue => e
42
+ response = e.response
43
+ end
44
+
45
+ JSON.parse(response)
46
+ end
47
+
48
+ # when you don't pass a parameter, it calls the "sanity check" user endpoint
49
+ def user(viggle_member_id = nil)
50
+ user_api = @api['user']
51
+ params = nil
52
+
53
+ if viggle_member_id
54
+ user_api = user_api[viggle_member_id]
55
+ end
56
+
57
+ begin
58
+ response = user_api.get headers
59
+ rescue => e
60
+ response = e.response
61
+ end
62
+
63
+ JSON.parse(response)
64
+ end
65
+
66
+ # @param viggle_member_id [String] required
67
+ # @param params [Hash] user profile data to send to Viggle
68
+ def update(params = {})
69
+ params.merge({
70
+ token: @token,
71
+ memberId: params[:memberId],
72
+ authentication: auth(@token + params[:memberId])
73
+ })
74
+
75
+ begin
76
+ response = @api['update'].post params.to_json, headers
77
+ rescue => e
78
+ response = e.response
79
+ end
80
+
81
+ JSON.parse(response)
82
+ end
83
+
84
+ ##
85
+ # Points Endpoints
86
+ ##
87
+
88
+ def deposit(params = {})
89
+ params = {
90
+ token: @token,
91
+ authentication: auth(@token + params[:viggleMemberId] + params[:pointsToDeposit].to_s + params[:partnerTransactionId] + params[:campaign] + params[:transactionType] + params[:actionType])
92
+ }.merge(params)
93
+
94
+ begin
95
+ @api['deposit'].post params.to_json, headers
96
+ rescue => e
97
+ response = e.response
98
+ end
99
+
100
+ JSON.parse(response)
101
+ end
102
+
103
+ # def withdraw(viggle_member_id, params = {})
104
+ # params = {
105
+ # token: @token,
106
+ # viggleMemberId: viggle_member_id,
107
+ # authentication: auth(viggle_member_id + params[:pointsToDeposit] + params[:partnerTransactionId] + params[:campaign] + params[:transactionType] + params[:actionType])
108
+ # }.merge(params)
109
+ #
110
+ # begin
111
+ # @api['withdraw'].post params.to_json, headers
112
+ # rescue => e
113
+ # response = e.response
114
+ # end
115
+ #
116
+ # JSON.parse(response)
117
+ # end
118
+
119
+ private
120
+
121
+ ##
122
+ # Utilities
123
+ ##
124
+
125
+ def headers
126
+ auth_date = Time.now.utc.iso8601
127
+ {
128
+ 'x-access-key' => @key,
129
+ 'x-authorization-date' => auth_date,
130
+ 'x-authorization' => auth(auth_date),
131
+ 'Content-Type' => 'application/json',
132
+ 'Accept' => 'application/json'
133
+ }
134
+ end
135
+
136
+ def auth(string)
137
+ Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), @secret, string)).chomp
138
+ end
139
+
140
+ end # class Api
141
+
142
+ end
@@ -0,0 +1,3 @@
1
+ module Viggles
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'viggles/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "viggles"
8
+ spec.version = Viggles::VERSION
9
+ spec.authors = ["Sathya Sekaran"]
10
+ spec.email = ["sfsekaran@gmail.com"]
11
+
12
+ # if spec.respond_to?(:metadata)
13
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
14
+ # end
15
+
16
+ spec.summary = %q{A Viggle Points API Gem}
17
+ spec.description = %q{Use viggles to update points balances, administrate users, and perform other actions.}
18
+ spec.homepage = "http://github.com/sfsekaran/viggles"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.8"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+
29
+ spec.add_runtime_dependency "rest-client", "~> 1.6.7"
30
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: viggles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sathya Sekaran
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.7
55
+ description: Use viggles to update points balances, administrate users, and perform
56
+ other actions.
57
+ email:
58
+ - sfsekaran@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - .travis.yml
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/viggles.rb
74
+ - lib/viggles/version.rb
75
+ - viggles.gemspec
76
+ homepage: http://github.com/sfsekaran/viggles
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.6
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A Viggle Points API Gem
100
+ test_files: []