genomelink-ruby 0.1.0

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: 2270964d1f0c7e9caebcac3d1eebc84f818d9a1d
4
+ data.tar.gz: dd78659f160ef24796d1cd822d7c26508d776d82
5
+ SHA512:
6
+ metadata.gz: c9ea8b1b08b1ba3006038ba1cb31e314641c493926e041b62fa1753e982ead01042a937b0ad6ec8ba992181750de862c46537b0b86a1a5aa79fee37fc6ed9557
7
+ data.tar.gz: 187dddc09294d7977d371849f75d24f679137c00d50f06a7036d3510b84963e1e2b6b6b448e48ecaad0f17a9ca9f61a7f2cfb3e0da4e1617e8985786adc63815
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # byebug files
11
+ .byebug*
12
+
13
+ # ctags
14
+ .tags*
15
+
16
+ # rspec failure tracking
17
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in genomelink-ruby.gemspec
6
+ gemspec
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ genomelink-ruby (0.1.0)
5
+ oauth2
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (9.1.0)
11
+ diff-lcs (1.3)
12
+ faraday (0.12.2)
13
+ multipart-post (>= 1.2, < 3)
14
+ jwt (1.5.6)
15
+ multi_json (1.13.1)
16
+ multi_xml (0.6.0)
17
+ multipart-post (2.0.0)
18
+ oauth2 (1.4.0)
19
+ faraday (>= 0.8, < 0.13)
20
+ jwt (~> 1.0)
21
+ multi_json (~> 1.3)
22
+ multi_xml (~> 0.5)
23
+ rack (>= 1.2, < 3)
24
+ rack (2.0.4)
25
+ rake (10.5.0)
26
+ rspec (3.7.0)
27
+ rspec-core (~> 3.7.0)
28
+ rspec-expectations (~> 3.7.0)
29
+ rspec-mocks (~> 3.7.0)
30
+ rspec-core (3.7.1)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-expectations (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-mocks (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-support (3.7.1)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.16)
45
+ byebug
46
+ genomelink-ruby!
47
+ rake (~> 10.0)
48
+ rspec (~> 3.0)
49
+
50
+ BUNDLED WITH
51
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ashwin Subramanian
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,56 @@
1
+
2
+ # GENOME LINK Ruby Gem
3
+
4
+ Ruby gem library to quickly get started with the GENOME LINK API. This supports both the authentication mechanisms, token based and OAuth 2.0.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'genomelink-ruby'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install genomelink-ruby
21
+
22
+ ## Usage/Examples
23
+ Example Usage for calling the reports API with oAuth token
24
+ ```ruby
25
+ 2.4.2 :001 > require 'genomelink'
26
+ => true
27
+ 2.4.2 :002 > result = Genomelink::Report.fetch("eye-color","GENOMELINKTEST001")
28
+ => #<Genomelink::Report:0x00007f87b41fb010 @phenotype={"url_name"=>"eye-color", "display_name"=>"Genetic eye color", "category"=>"trait"}, @population="european", @scores=[{"score"=>0, "text"=>"Tend to not have brown eyes"}, {"score"=>1, "text"=>"Tend to not have brown eyes, slightly"}, {"score"=>2, "text"=>"Intermediate"}, {"score"=>3, "text"=>"Slight tendency for brown eyes"}, {"score"=>4, "text"=>"Stronger tendency for brown eyes"}], @summary={"score"=>0, "text"=>"Tend to not have brown eyes", "warnings"=>[]}>
29
+ 2.4.2 :003 > result.summary
30
+ => {"score"=>0, "text"=>"Tend to not have brown eyes", "warnings"=>[]}
31
+ ```
32
+
33
+ Example Usage for oAuth -
34
+ ```ruby
35
+ # To get the redirect URL :
36
+ redirect_url = Genomelink::Oauth.authorization_url("report:eye-color")
37
+ # Redirect user to the above URL.
38
+ # After authentication user control reaches the callback URL with code.
39
+ # Use the code from the parameters and request a token
40
+ token = Genomelink::Oauth.get_token(params[:code])
41
+ # This token can be used to call the reports API as given above.
42
+ # Store this token and if it expired use the code again to get a new token.
43
+ ```
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To run only the unit tests, run the specs in `spec/unit`. The integration specs which reach out to genomelink are in `spec/integration`
47
+
48
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/s-ashwinkumar/genomelink-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "genomelink"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "genomelink/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "genomelink-ruby"
8
+ spec.version = Genomelink::VERSION
9
+ spec.authors = ["Ashwin Subramanian"]
10
+ spec.email = ["s.ashwinkumar24902gmail.com"]
11
+
12
+ spec.summary = %q{Ruby Gem to access genome link APIs}
13
+ spec.description = %q{This is a ruby gem to access the genome link APIs. It inclides the API classes and the OAuth system.}
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "byebug"
26
+ spec.add_dependency "oauth2"
27
+ end
@@ -0,0 +1,10 @@
1
+ require "genomelink/version"
2
+ require "genomelink/base"
3
+ require "genomelink/reports"
4
+ require "genomelink/oauth"
5
+
6
+ module Genomelink
7
+ SITE = 'https://genomelink.io'.freeze
8
+ # Path for genomelinke oauth
9
+ OAUTH_PATH = "#{SITE}/oauth/authorize".freeze
10
+ end
@@ -0,0 +1,47 @@
1
+ require 'oauth2'
2
+
3
+ module Genomelink
4
+ class ConfigNotFound < StandardError; end
5
+ # The Base class for all of the other class.
6
+ # Let other classes inherit from here and put common methods here.
7
+ #
8
+ # @author [ashwin]
9
+ #
10
+ class Base
11
+ class << self
12
+ # Makes a get request to genomelink for the URL given and with the given token.
13
+ # TODO : use meta programming and define all Restful methods.
14
+ # @param path [String] the path to hit for the request.
15
+ # @param token [String] the access token to be used.
16
+ #
17
+ # @return [Hash] The response Json parsed as a hash.
18
+ def get(path, token)
19
+ result = service(token).get do |req|
20
+ req.url path
21
+ req.headers['Authorization'] = "BEARER #{token}"
22
+ end
23
+ JSON.parse(result.body)
24
+ end
25
+
26
+ private
27
+
28
+ # gets a genomelink API service/client
29
+ # @param token [String] Access token.
30
+ #
31
+ # @return [OAuth2::AccessToken] An initialized AccessToken instance that acts as service client
32
+ def service(token)
33
+ @service ||= Faraday.new(url: SITE)
34
+ end
35
+ end
36
+
37
+ # A constructor to take a hash and assign it to the instance variables
38
+ # @param options = {} [Hash] Could by any class's hash, but the first level keys should be defined in the class
39
+ #
40
+ # @return [Subclass os Base] Returns object of any subclass like Report
41
+ def initialize(options = {})
42
+ options.each do |attribute, value|
43
+ instance_variable_set("@#{attribute}", value)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,4 @@
1
+ module Genomelink
2
+ class Genome < Base
3
+ end
4
+ end
@@ -0,0 +1,47 @@
1
+ module Genomelink
2
+ # Oauth class to take care of the Oauth 2.0 with genomelink APIs
3
+ #
4
+ # @author [ashwin]
5
+ #
6
+ class Oauth < Base
7
+ class << self
8
+ # Used to get the redirect URL to Genomelink where user can authorize an app.
9
+ # @param scope [String] Space delimited list of scopes that specify what the user can access
10
+ # EXAMPLE : "report:bmi report:longevity"
11
+ # This should be within the ones selected during the registering the client application.
12
+ #
13
+ # @return [String] URL where user needs to be redirected for authorization
14
+ def authorization_url(scope)
15
+ client.auth_code.authorize_url(redirect_uri: get_config('GENOMELINK_CALLBACK_URL'), scope: scope)
16
+ end
17
+
18
+ # [get_token description]
19
+ # @param auth_code [String] This is the code that is returned after use visits and authorizes on the authorization URL
20
+ #
21
+ # @return [String] Access token that can be used to access the genomelink API.
22
+ def get_token(auth_code)
23
+ client.auth_code.get_token(auth_code, redirect_uri: get_config('GENOMELINK_CALLBACK_URL')).token
24
+ end
25
+
26
+ private
27
+ # gets the Oauth Client object
28
+ #
29
+ # @return [OAuth2::Client] A Oauth Client object.
30
+ def client
31
+ @client ||= OAuth2::Client.new( get_config('GENOMELINK_CLIENT_ID'),
32
+ get_config('GENOMELINK_CLIENT_SECRET'),
33
+ :site => OAUTH_PATH
34
+ )
35
+ end
36
+
37
+ # gets a gicen env variable, checks for existence and throws exception if not present
38
+ # @param config_name [String] key of the env variable
39
+ #
40
+ # @return [String] value of the env variable
41
+ def get_config(config_name)
42
+ raise ConfigNotFound, "Environment variable #{config_name} not found !" unless ENV[config_name]
43
+ ENV[config_name]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,28 @@
1
+ module Genomelink
2
+ # Report class to represent the reports API
3
+ #
4
+ # @author [ashwin]
5
+ #
6
+ class Report < Base
7
+ attr_accessor :summary, :phenotype, :population, :scores
8
+ class << self
9
+ # Method to get the report for a given trait.
10
+ # @param trait [String] A particular trait to fetch details for.
11
+ # @param token [Sting] Access token to be used.
12
+ #
13
+ # @return [Report] A report object with summary, phenotype, population and scores.
14
+ def fetch(trait, token)
15
+ new get(path_to_trait(trait), token)
16
+ end
17
+
18
+ private
19
+ # Method to return the path to hit to get report of a trait
20
+ # @param trait [String] A particular trait to fetch details for.
21
+ #
22
+ # @return [String] path for the URL/request
23
+ def path_to_trait(trait)
24
+ "/v1/reports/#{trait}?population=european"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Genomelink
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genomelink-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ashwin Subramanian
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-12 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: 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: oauth2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: This is a ruby gem to access the genome link APIs. It inclides the API
84
+ classes and the OAuth system.
85
+ email:
86
+ - s.ashwinkumar24902gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - genomelink-ruby.gemspec
102
+ - lib/genomelink.rb
103
+ - lib/genomelink/base.rb
104
+ - lib/genomelink/genome.rb
105
+ - lib/genomelink/oauth.rb
106
+ - lib/genomelink/reports.rb
107
+ - lib/genomelink/version.rb
108
+ homepage:
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.14
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Ruby Gem to access genome link APIs
132
+ test_files: []