agecheq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4dd4472984464ddcb34687ac16ad7ae40be825c
4
+ data.tar.gz: 53ae5262a0baf1de56181a5e3d1563d2f31d1d70
5
+ SHA512:
6
+ metadata.gz: 2d742d62881f58f2ef3dc34c6ac2141fb80ded5f39c5914326a85236d86619b0fef93f186988fede593171f6320f9fcf666894b11dc5f02238c862e1739b13a8
7
+ data.tar.gz: 56389b3bd1a1240b0cd38a89ced2e7b3c48bed7b1d54723a39c74b50ada4efdb6a6572b32b83262fbaed24e51d438160b3e775bd1106d82ba11f4ac76e72e944
@@ -0,0 +1,48 @@
1
+ # AgeCheq API Client for Ruby
2
+
3
+ This is a simple [HTTParty](http://johnnunemaker.com/httparty/) wrapper around the [AgeCheq](http://www.agecheq.com/) API.
4
+
5
+ ## Installation
6
+
7
+ Add `agecheq` to your Gemfile.
8
+
9
+ ```ruby
10
+ gem 'agecheq'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ You must first configure the gem with your developer key and application id. Both can be obtained from the [AgeCheq Developer Dashboard](http://developer.agecheq.com/).
16
+
17
+ ```ruby
18
+ AgeCheq.configure do |config|
19
+ config.api_key = "ABCD"
20
+ config.application_id = "XYZ"
21
+ end
22
+ ```
23
+
24
+ ### Status Check
25
+
26
+ Check the status of an AgeCheq PIN and your application using:
27
+
28
+ ```ruby
29
+ AgeCheq::Child.check('AGECHEQ_PIN')
30
+ OR
31
+ child = AgeCheq::Child.new('AGECHEQ_PIN')
32
+ child.status
33
+ ```
34
+
35
+ ### Associate Data
36
+
37
+ Associate data with an AgeCheq PIN and your application using:
38
+
39
+ ```ruby
40
+ AgeCheq::Child.associate('AGECHEQ_PIN', 'DATA')
41
+ OR
42
+ child = AgeCheq::Child.new('AGECHEQ_PIN')
43
+ child.associate('DATA')
44
+ ```
45
+
46
+ ## Testing
47
+
48
+ Testing is done with RSpec and executed using `bundle exec rspec`.
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Quirkyapi'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,19 @@
1
+ require 'httparty'
2
+
3
+ require 'agecheq/configuration'
4
+ require 'agecheq/version'
5
+ require 'agecheq/child'
6
+
7
+ module AgeCheq
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield(configuration)
14
+ end
15
+
16
+ def self.reset!
17
+ @configuration = Configuration.new
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ require 'agecheq/response_parser'
2
+
3
+ module AgeCheq
4
+ class Child
5
+ include HTTParty
6
+
7
+ format :json
8
+ parser ResponseParser
9
+
10
+ # Shortcut methods for initializing and making an API call in one line.
11
+ class << self
12
+ def check(pin)
13
+ self.new(pin).check
14
+ end
15
+
16
+ def associate(pin, data)
17
+ self.new(pin).associate(data)
18
+ end
19
+
20
+ def configure!
21
+ raise 'You must set the api_key and application_id using configure' unless AgeCheq.configuration.configured?
22
+ basic_auth AgeCheq.configuration.api_key, ' '
23
+ base_uri 'https://api.agecheq.com/applications/' + AgeCheq.configuration.application_id
24
+ end
25
+ end
26
+
27
+ attr_reader :pin
28
+
29
+ def initialize(pin)
30
+ @pin = pin
31
+ self.class.configure!
32
+ end
33
+
34
+ # Check the status of a child using their pin.
35
+ def check
36
+ response = self.class.get("/acpin/#{@pin}/check")
37
+ response.parsed_response
38
+ end
39
+
40
+ # Associate some data with a child's account.
41
+ def associate(data)
42
+ response = self.class.get("/acpin/#{@pin}/associate/#{data}")
43
+ response.parsed_response
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
3
+ module AgeCheq
4
+ class Configuration
5
+ attr_accessor :api_key
6
+ attr_accessor :application_id
7
+
8
+ def initialize
9
+ @api_key = ""
10
+ @application_id = ""
11
+ end
12
+
13
+ def configured?
14
+ !api_key.blank? && !application_id.blank?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_support/hash_with_indifferent_access'
2
+
3
+ module AgeCheq
4
+ InvalidCommand = Class.new(StandardError)
5
+ InvalidAgeCheqPin = Class.new(StandardError)
6
+ UnknownFailure = Class.new(StandardError)
7
+
8
+ class ResponseParser < HTTParty::Parser
9
+ def parse
10
+ response = JSON.parse(body)
11
+
12
+ # Check for a failure response.
13
+ if response['rtn'] == 'fail'
14
+ if response['rtnmsg'] == 'invalid command'
15
+ raise InvalidCommand, response['rtnmsg']
16
+ elsif response['rtnmsg'] == 'invalid child agecheq pin'
17
+ raise InvalidAgeCheqPin, response['rtnmsg']
18
+ else
19
+ raise UnknownFailure, response['rtnmsg']
20
+ end
21
+ end
22
+
23
+ # Return data as a HWIA.
24
+ ActiveSupport::HashWithIndifferentAccess.new(response['data'])
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module AgeCheq
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: agecheq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Quirky Development
8
+ - Adam Michel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-07-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">"
33
+ - !ruby/object:Gem::Version
34
+ version: '4.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">"
40
+ - !ruby/object:Gem::Version
41
+ version: '4.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: webmock
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: faker
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: AgeCheq is a thin Ruby wrapper around the AgeCheq API.
85
+ email:
86
+ - platform@quirky.com
87
+ - amichel@quirky.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - README.md
93
+ - Rakefile
94
+ - lib/agecheq.rb
95
+ - lib/agecheq/child.rb
96
+ - lib/agecheq/configuration.rb
97
+ - lib/agecheq/response_parser.rb
98
+ - lib/agecheq/version.rb
99
+ homepage: https://www.quirky.com
100
+ licenses: []
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.5
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: AgeCheq is a thin Ruby wrapper around the AgeCheq API.
122
+ test_files: []