qoolife-api 0.0.3
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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +5 -0
- data/lib/qoolife-api.rb +21 -0
- data/lib/qoolife-api/attachment.rb +4 -0
- data/lib/qoolife-api/base.rb +24 -0
- data/lib/qoolife-api/comment.rb +4 -0
- data/lib/qoolife-api/conversation.rb +6 -0
- data/lib/qoolife-api/eager_load.rb +32 -0
- data/lib/qoolife-api/errors.rb +16 -0
- data/lib/qoolife-api/hello.rb +8 -0
- data/lib/qoolife-api/journal_entry.rb +7 -0
- data/lib/qoolife-api/measurement.rb +4 -0
- data/lib/qoolife-api/paginated_collection.rb +27 -0
- data/lib/qoolife-api/pagination.rb +24 -0
- data/lib/qoolife-api/post.rb +5 -0
- data/lib/qoolife-api/questionnaire.rb +5 -0
- data/lib/qoolife-api/questionnaire_response.rb +5 -0
- data/lib/qoolife-api/user.rb +4 -0
- data/lib/qoolife-api/variable.rb +4 -0
- data/lib/qoolife-api/version.rb +3 -0
- data/qoolife_api.gemspec +28 -0
- data/spec/qoolife_api_spec.rb +31 -0
- data/spec/spec_helper.rb +2 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 131cd58b0d6d85a8a1931db7cbd47ae1fcc6fa1e
|
4
|
+
data.tar.gz: 9021165ff6d7c19f965586be65895299502544ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d09dff5d1a700c1af669fe2308a3b2316dd76544149341e62cdcb8e70945c4366fe5b405116cb72b91d966da71dc77e960ad111025953485b8877b6c1ca44e8
|
7
|
+
data.tar.gz: 6e76bbf153cc531a8338b321a9475c0e8ffb21cf14169b432852b4a5ab27a8eea69d531a0feff7fbf51c3b2bfb002d58bf1d8da6383fc6009460d23a281773f2
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 David Gil
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# QoolifeApi - Ruby client for Qoolife API
|
2
|
+
|
3
|
+
Ruby API client for [Qoolife](https://qoolife.com), so you can easily plug it into your App.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'qoolife-api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install qoolife-api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Most of QoolifeApi methods need authentication with a Qoolife account. You need to provide this data to the client like this:
|
22
|
+
|
23
|
+
QoolifeApi.authenticate 'myuser@example.com', 'veeerysekret'
|
24
|
+
|
25
|
+
After that, you can retrieve resources from the API using `ActiveResource` syntax.
|
26
|
+
|
27
|
+
Some examples:
|
28
|
+
|
29
|
+
QoolifeApi::JournalEntries.all # will retrieve a paginated collection of the authenticated users' journal entries
|
30
|
+
QoolifeApi::JournalEntries.last.measurements # measurements from the last journal entry
|
31
|
+
QoolifeApi::Conversation.all # conversations of any kind where the user is watcher.
|
32
|
+
QoolifeApi::Conversation.last.posts.last # last message post in the last conversation where the user is watcher.
|
33
|
+
|
34
|
+
Check the [API docs](http://developer.qoolife.com) for a full reference of what Qoolife API can do.
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( https://github.com/[my-github-username]/qoolife-api/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/qoolife-api.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# needed because the gem name is different from the require name and the gemspec does not support specifying the require path as in Gemfiles
|
2
|
+
require 'active_resource'
|
3
|
+
# needed for REST pagination
|
4
|
+
require 'activeresource-response'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
require "qoolife-api/version"
|
8
|
+
|
9
|
+
require 'qoolife-api/pagination'
|
10
|
+
require 'qoolife-api/paginated_collection'
|
11
|
+
require 'qoolife-api/base'
|
12
|
+
require 'qoolife-api/eager_load'
|
13
|
+
require 'qoolife-api/errors'
|
14
|
+
|
15
|
+
require 'qoolife-api/hello'
|
16
|
+
|
17
|
+
require 'qoolife-api/conversation'
|
18
|
+
require 'qoolife-api/journal_entry'
|
19
|
+
require 'qoolife-api/measurement'
|
20
|
+
require 'qoolife-api/post'
|
21
|
+
require 'qoolife-api/questionnaire'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module QoolifeApi
|
2
|
+
class Base < ActiveResource::Base
|
3
|
+
include Pagination
|
4
|
+
|
5
|
+
self.site = 'https://qoolife.com'
|
6
|
+
self.prefix = '/api/v1/'
|
7
|
+
|
8
|
+
self.include_root_in_json = true
|
9
|
+
self.collection_parser = PaginatedCollection
|
10
|
+
|
11
|
+
def self.endpoint
|
12
|
+
"#{site}#{prefix}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.token=(token)
|
16
|
+
self.headers['Authorization'] = "Bearer #{token}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.authorize(user, password)
|
20
|
+
self.user = user
|
21
|
+
self.password = password
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# need eager loading base resources to avoid circular references when declaring has_X associations
|
2
|
+
module QoolifeApi
|
3
|
+
class Attachment < Base
|
4
|
+
end
|
5
|
+
|
6
|
+
class Comment < Base
|
7
|
+
end
|
8
|
+
|
9
|
+
class Conversation < Base
|
10
|
+
end
|
11
|
+
|
12
|
+
class JournalEntry < Base
|
13
|
+
end
|
14
|
+
|
15
|
+
class Measurement < Base
|
16
|
+
end
|
17
|
+
|
18
|
+
class Post < Base
|
19
|
+
end
|
20
|
+
|
21
|
+
class Questionnaire < Base
|
22
|
+
end
|
23
|
+
|
24
|
+
class QuestionnaireResponse < Base
|
25
|
+
end
|
26
|
+
|
27
|
+
class User < Base
|
28
|
+
end
|
29
|
+
|
30
|
+
class Variable < Base
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module QoolifeApi
|
2
|
+
class ActiveResource::Errors
|
3
|
+
def from_hash_with_pre_processing(messages, save_cache = false)
|
4
|
+
new_messages = if messages['error'] == 'invalid_resource'
|
5
|
+
messages['messages']
|
6
|
+
else
|
7
|
+
messages
|
8
|
+
end
|
9
|
+
|
10
|
+
from_hash_without_pre_processing(new_messages,save_cache)
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_method :from_hash_without_pre_processing, :from_hash
|
14
|
+
alias_method :from_hash, :from_hash_with_pre_processing
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module QoolifeApi
|
2
|
+
class PaginatedCollection < ActiveResource::Collection
|
3
|
+
attr_accessor :first_page, :prev_page, :next_page, :last_page
|
4
|
+
|
5
|
+
def initialize(elements = [])
|
6
|
+
@elements = elements
|
7
|
+
response = QoolifeApi::Base.connection.http_response
|
8
|
+
response = pagination_header_response_to_hash response['Link']
|
9
|
+
@first_page = response[:first]
|
10
|
+
@prev_page = response[:prev]
|
11
|
+
@next_page = response[:next]
|
12
|
+
@last_page = response[:last]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def pagination_header_response_to_hash(response)
|
18
|
+
response.to_s.split(',').each_with_object({}) do |item, h|
|
19
|
+
items = item.split(';')
|
20
|
+
key = items.last.gsub('rel=', '').gsub("\"", '').to_sym
|
21
|
+
value = items.first
|
22
|
+
|
23
|
+
h[key] = value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module QoolifeApi
|
2
|
+
module Pagination
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
base.add_response_method :http_response
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def find_all_across_pages(options = {})
|
10
|
+
collection = []
|
11
|
+
options[:params] ||= {}
|
12
|
+
options[:params][:page] = 1
|
13
|
+
|
14
|
+
begin
|
15
|
+
batch = find(:all, options)
|
16
|
+
collection += batch.to_a
|
17
|
+
options[:params][:page] += 1
|
18
|
+
end while batch.pagination['next'].present?
|
19
|
+
|
20
|
+
collection
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/qoolife_api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qoolife-api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qoolife-api"
|
8
|
+
spec.version = QoolifeApi::VERSION
|
9
|
+
spec.authors = ["David Gil"]
|
10
|
+
spec.email = ["dgilperez@qoolife.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper for Qoolife API}
|
12
|
+
spec.description = %q{Ruby API client for Qoolife, so you can easily plug it into your App}
|
13
|
+
spec.homepage = "https://github.com/qoolife/qoolife-api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry-byebug"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'activeresource', '~> 4.0'
|
27
|
+
spec.add_runtime_dependency 'activeresource-response', '~> 1.0'
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe QoolifeApi do
|
5
|
+
describe "hello world" do
|
6
|
+
it "should answer world when said hello" do
|
7
|
+
expect(QoolifeApi::Hello.say_hello).to eq({ 'hello' => 'world' })
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "journal entries" do
|
12
|
+
it "should return 401 unauthorized for unauthorized user" do
|
13
|
+
expect { QoolifeApi::JournalEntry.all }.to raise_error(ActiveResource::UnauthorizedAccess)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should list journal entries for authorized user" do
|
17
|
+
authorize!
|
18
|
+
|
19
|
+
all_entries = QoolifeApi::JournalEntry.all
|
20
|
+
|
21
|
+
expect(all_entries.size).to eq(20)
|
22
|
+
expect(all_entries.first).to be_a(QoolifeApi::JournalEntry)
|
23
|
+
expect(all_entries.first.attributes.keys).to eq(["id", "user_id", "author_id", "body", "date", "created_at", "measurements", "questionnaire_responses"])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorize!
|
28
|
+
# use your own credentials to test
|
29
|
+
QoolifeApi::Base.authorize 'youruser', 'yourpassword'
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qoolife-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Gil
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-26 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activeresource
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activeresource-response
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
description: Ruby API client for Qoolife, so you can easily plug it into your App
|
98
|
+
email:
|
99
|
+
- dgilperez@qoolife.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/qoolife-api.rb
|
111
|
+
- lib/qoolife-api/attachment.rb
|
112
|
+
- lib/qoolife-api/base.rb
|
113
|
+
- lib/qoolife-api/comment.rb
|
114
|
+
- lib/qoolife-api/conversation.rb
|
115
|
+
- lib/qoolife-api/eager_load.rb
|
116
|
+
- lib/qoolife-api/errors.rb
|
117
|
+
- lib/qoolife-api/hello.rb
|
118
|
+
- lib/qoolife-api/journal_entry.rb
|
119
|
+
- lib/qoolife-api/measurement.rb
|
120
|
+
- lib/qoolife-api/paginated_collection.rb
|
121
|
+
- lib/qoolife-api/pagination.rb
|
122
|
+
- lib/qoolife-api/post.rb
|
123
|
+
- lib/qoolife-api/questionnaire.rb
|
124
|
+
- lib/qoolife-api/questionnaire_response.rb
|
125
|
+
- lib/qoolife-api/user.rb
|
126
|
+
- lib/qoolife-api/variable.rb
|
127
|
+
- lib/qoolife-api/version.rb
|
128
|
+
- qoolife_api.gemspec
|
129
|
+
- spec/qoolife_api_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: https://github.com/qoolife/qoolife-api
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.2.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Ruby wrapper for Qoolife API
|
155
|
+
test_files:
|
156
|
+
- spec/qoolife_api_spec.rb
|
157
|
+
- spec/spec_helper.rb
|