diff --git a/lib/transcriptic_kit/client.rb b/lib/transcriptic_kit/client.rb index d230069..7e1ca59 100644 --- a/lib/transcriptic_kit/client.rb +++ b/lib/transcriptic_kit/client.rb @@ -1,6 +1,6 @@ require 'faraday' -TRANSCRIPTIC_URL = "https://secure.transcriptic.com/" +TRANSCRIPTIC_URL = "https://secure.transcriptic.com/api" module TranscripticKit @@ -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 @@ -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', diff --git a/lib/transcriptic_kit/mappings/organization_mapping.rb b/lib/transcriptic_kit/mappings/organization_mapping.rb index 916c9bd..9bf0bda 100644 --- a/lib/transcriptic_kit/mappings/organization_mapping.rb +++ b/lib/transcriptic_kit/mappings/organization_mapping.rb @@ -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 diff --git a/lib/transcriptic_kit/mappings/project_mapping.rb b/lib/transcriptic_kit/mappings/project_mapping.rb index f211582..227f81e 100644 --- a/lib/transcriptic_kit/mappings/project_mapping.rb +++ b/lib/transcriptic_kit/mappings/project_mapping.rb @@ -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 diff --git a/lib/transcriptic_kit/mappings/run_mapping.rb b/lib/transcriptic_kit/mappings/run_mapping.rb index b31b6ee..3275bba 100644 --- a/lib/transcriptic_kit/mappings/run_mapping.rb +++ b/lib/transcriptic_kit/mappings/run_mapping.rb @@ -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 diff --git a/lib/transcriptic_kit/models/organization.rb b/lib/transcriptic_kit/models/organization.rb index 503879d..4a21914 100644 --- a/lib/transcriptic_kit/models/organization.rb +++ b/lib/transcriptic_kit/models/organization.rb @@ -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 diff --git a/lib/transcriptic_kit/models/project.rb b/lib/transcriptic_kit/models/project.rb index 80b2621..7273aa3 100644 --- a/lib/transcriptic_kit/models/project.rb +++ b/lib/transcriptic_kit/models/project.rb @@ -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 diff --git a/lib/transcriptic_kit/models/run.rb b/lib/transcriptic_kit/models/run.rb index fbd8482..b7781ea 100644 --- a/lib/transcriptic_kit/models/run.rb +++ b/lib/transcriptic_kit/models/run.rb @@ -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 diff --git a/lib/transcriptic_kit/resources/organization_resource.rb b/lib/transcriptic_kit/resources/organization_resource.rb index 1b88f38..6186ac6 100644 --- a/lib/transcriptic_kit/resources/organization_resource.rb +++ b/lib/transcriptic_kit/resources/organization_resource.rb @@ -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 diff --git a/lib/transcriptic_kit/resources/project_resource.rb b/lib/transcriptic_kit/resources/project_resource.rb index bc7361e..2137366 100644 --- a/lib/transcriptic_kit/resources/project_resource.rb +++ b/lib/transcriptic_kit/resources/project_resource.rb @@ -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 @@ -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 diff --git a/lib/transcriptic_kit/resources/run_resource.rb b/lib/transcriptic_kit/resources/run_resource.rb index 533b631..6741f5f 100644 --- a/lib/transcriptic_kit/resources/run_resource.rb +++ b/lib/transcriptic_kit/resources/run_resource.rb @@ -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]) @@ -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 diff --git a/transcriptic_kit.gemspec b/transcriptic_kit.gemspec index f46fbc5..8870912 100644 --- a/transcriptic_kit.gemspec +++ b/transcriptic_kit.gemspec @@ -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