Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/transcriptic_kit/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'faraday'

TRANSCRIPTIC_URL = "https://secure.transcriptic.com/"
TRANSCRIPTIC_URL = "https://secure.transcriptic.com/api"


module TranscripticKit
Expand All @@ -17,13 +17,14 @@ def initialize(options = {})
def connection
Faraday.new(connection_options) do |req|
req.adapter :net_http
req.response :logger, nil, { headers: true, bodies: true }
end
end

def self.resources
{
projects: ProjectResource,
organization: OrganizationResource,
organizations: OrganizationResource,
runs: RunResource
}
end
Expand All @@ -45,7 +46,7 @@ def resources

def connection_options
{
url: TRANSCRIPTIC_URL + "/#{@org_name}",
url: TRANSCRIPTIC_URL,
headers: {
content_type: 'application/json',
accept: 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions lib/transcriptic_kit/mappings/organization_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class OrganizationMapping

kartograph do
mapping Organization
root_key plural: 'results', scopes: [:read]
root_key plural: 'data', singular: 'data', scopes: [:read]

property :id, :name, :created_at, :subdomain, :profile_photo_attachment_url, :collaborators, :addresses, scopes: [:read]
property :id, :attributes, scopes: [:read]
end
end
end
9 changes: 3 additions & 6 deletions lib/transcriptic_kit/mappings/project_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ class ProjectMapping

kartograph do
mapping Project
root_key plural: 'results', scopes: [:read]
root_key singular: 'project', scopes: [:update]

property :name, :webhook_url, :bsl, scopes: [:read, :create]
property :id, :created_at, :updated_at, :archived_at, :users, scopes: [:read]
property :name, :bsl, :webhook_url, scopes: [:update]
root_key plural: 'data', singular: 'data', scopes: [:read]
property :id, :attributes, scopes:[:read]
# property :name, :attributes, scopes:[:read, :update, :create]
end
end
end
8 changes: 5 additions & 3 deletions lib/transcriptic_kit/mappings/run_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ class RunMapping

kartograph do
mapping Run
root_key singular: 'run', scopes: [:update]
root_key plural: 'data', singular: 'data', scopes: [:read]

property :id, :title, :status, :created_at, :accepted_at, :started_at, :refs, :instructions, :updated_at, :completed_at, :results, :progress, :total_cost, :bsl, :owner, scopes: [:read]
property :title, :test_mode, :protocol, scopes: [:create]
property :id, :attributes, scopes: [:read]

## Create not yet avaiable on the JSON API
# property :attributes, scopes: [:create]
# property :refs, :instructions, key: "protocol", scopes: [:create]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/transcriptic_kit/models/organization.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module TranscripticKit
class Organization < BaseModel
[:id, :name, :created_at, :subdomain, :profile_photo_attachment_url, :collaborators, :addresses].each do |key|
[:id, :name, :created_at, :subdomain].each do |key|
attribute(key)
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/transcriptic_kit/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module TranscripticKit
class Project < BaseModel
[:id, :name, :created_at, :updated_at, :archived_at, :webhook_url, :bsl, :users].each do |key|
[:id, :name, :created_at, :updated_at, :archived_at, :webhook_url, :bsl].each do |key|
attribute(key)
end
attribute :name
attribute :bsl
end
end
12 changes: 7 additions & 5 deletions lib/transcriptic_kit/models/run.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module TranscripticKit
class Run < BaseModel
[:id, :status, :title, :protocol, :created_at, :accepted_at, :started_at, :updated_at, :completed_at, :results,
:test_mode, :progress, :total_cost, :bsl, :protocol, :refs, :instructions, :owner].each do |key|
:test_mode, :progress, :quote, :bsl, :protocol, :refs, :instructions, :owner].each do |key|
attribute(key)
end
#For creates
attribute :title
attribute :test_mode
attribute :protocol

#For creates not yet availble
# attribute :title
# attribute :test_mode
# attribute :protocol
# attribute :quote
end
end
34 changes: 31 additions & 3 deletions lib/transcriptic_kit/resources/organization_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,43 @@ def self.new(options)
@org_name = options[:org_name]

self.resources.each do |res|
res.instance_eval("@path = '#{@org_name}/#{res.path}'")
res.instance_eval("@path = '/api#{res.path}'")
end

super(connection: options[:connection])
end

resources do
default_handler(:ok) {|r| OrganizationMapping.extract_single(r.body, :read) }
get '' => :info
default_handler(422) { |response| ErrorMapping.extract_single(response.body, :read) }
default_handler(:ok, :created) { |response| OrganizationMapping.extract_single(response.body, :read) }
default_handler { |response| raise "Unexpected response status #{response.status}... #{response.inspect}" }

action :all do
verb :get
path "/organizations"
handler(200) { |response| OrganizationMapping.extract_collection(response.body, :read) }
end

action :find do
verb :get
path "/organizations/:id"
handler(200) { |response| OrganizationMapping.extract_single(response.body, :read) }
end

## Not yet available in the JSON API
# action :create do
# verb :post
# path "/projects"
# body { |object| ProjectMapping.representation_for(:create, object) }
# handler(202) { |response| ProjectMapping.extract_single(response.body, :read) }
# end
#
# action :update do
# verb :put
# path "projects/:id"
# body { |object| ProjectMapping.representation_for(:update, object) }
# handler(200) { |response, object| ProjectMapping.extract_into_object(object, response.body, :read) }
# end
end
end
end
36 changes: 18 additions & 18 deletions lib/transcriptic_kit/resources/project_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def self.new(options)
@org_name = options[:org_name]

self.resources.each do |res|
res.instance_eval("@path = '#{@org_name}/#{res.path}'")
res.instance_eval("@path = '/api#{res.path}'")
end

super(connection: options[:connection])
end

Expand All @@ -19,30 +19,30 @@ def self.new(options)

action :all do
verb :get
puts @org_name
path "projects.json"
path "/projects"
handler(200) { |response| ProjectMapping.extract_collection(response.body, :read) }
end

action :find do
verb :get
path ":id.json"
path "/projects/:id"
handler(200) { |response| ProjectMapping.extract_single(response.body, :read) }
end

action :create do
verb :post
path ""
body { |object| ProjectMapping.representation_for(:create, object) }
handler(202) { |response| ProjectMapping.extract_single(response.body, :read) }
end

action :update do
verb :put
path ":id"
body { |object| ProjectMapping.representation_for(:update, object) }
handler(200) { |response, object| ProjectMapping.extract_into_object(object, response.body, :read) }
end
## Not yet available in the JSON API
# action :create do
# verb :post
# path "/projects"
# body { |object| ProjectMapping.representation_for(:create, object) }
# handler(202) { |response| ProjectMapping.extract_single(response.body, :read) }
# end
#
# action :update do
# verb :put
# path "projects/:id"
# body { |object| ProjectMapping.representation_for(:update, object) }
# handler(200) { |response, object| ProjectMapping.extract_into_object(object, response.body, :read) }
# end
end
end
end
33 changes: 17 additions & 16 deletions lib/transcriptic_kit/resources/run_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.new(options)
@org_name = options[:org_name]

self.resources.each do |res|
res.instance_eval("@path = '#{@org_name}/#{res.path}'")
res.instance_eval("@path = '/api#{res.path}'")
end

super(connection: options[:connection])
Expand All @@ -19,29 +19,30 @@ def self.new(options)

action :all do
verb :get
path ':project_id/runs.json'
path '/runs'
handler(200) { |response| RunMapping.extract_collection(response.body, :read) }
end

action :find do
verb :get
path ':project_id/runs/:run_id.json'
path '/runs/:id'
handler(200) { |response| RunMapping.extract_single(response.body, :read) }
end

action :create do
verb :post
path ':project_id/runs'
body { |object| RunMapping.representation_for(:create, object) }
handler(202) { |response| RunMapping.extract_single(response.body, :read) }
end

action :update do
verb :put
path ':project_id/:run_id'
body { |object| RunMapping.representation_for(:update, object) }
handler(200) { |response, object| RunMapping.extract_into_object(object, response.body, :read) }
end
## Note yet available in JSON API
# action :create do
# verb :post
# path '/runs'
# body { |object| RunMapping.representation_for(:create, object) }
# handler(202) { |response| RunMapping.extract_single(response.body, :read) }
# end
#
# action :update do
# verb :put
# path ':project_id/:run_id'
# body { |object| RunMapping.representation_for(:update, object) }
# handler(200) { |response, object| RunMapping.extract_into_object(object, response.body, :read) }
# end
end
end
end
3 changes: 2 additions & 1 deletion transcriptic_kit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Gem::Specification.new do |spec|
spec.add_dependency "resource_kit", '~> 0.1.5'
spec.add_dependency "kartograph", '~> 0.2.4'
spec.add_dependency "activesupport", '> 3.0', '< 5.1'
spec.add_dependency "faraday", '~> 0.9.2'
spec.add_dependency "faraday", '~> 1.0.1' #0.9.2'
spec.add_dependency "dotenv", '~> 2.7.5'


end