Class: Panoptes::Client

Inherits:
Object
  • Object
show all
Includes:
Cellect, Comments, Discussions, Me, Projects, SubjectSets, Subjects, UserGroups, Workflows
Defined in:
lib/panoptes/client.rb,
lib/panoptes/client/me.rb,
lib/panoptes/client/cellect.rb,
lib/panoptes/client/version.rb,
lib/panoptes/client/comments.rb,
lib/panoptes/client/projects.rb,
lib/panoptes/client/subjects.rb,
lib/panoptes/client/workflows.rb,
lib/panoptes/client/discussions.rb,
lib/panoptes/client/user_groups.rb,
lib/panoptes/client/subject_sets.rb

Direct Known Subclasses

TalkClient

Defined Under Namespace

Modules: Cellect, Comments, Discussions, Me, Projects, SubjectSets, Subjects, UserGroups, Workflows Classes: ConnectionFailed, GenericError, NotLoggedIn, ResourceNotFound, ServerError

Constant Summary collapse

VERSION =
"0.2.10".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cellect

#cellect_subjects, #cellect_workflows

Methods included from Comments

#create_comment

Methods included from Discussions

#discussions

Methods included from Workflows

#create_workflow, #workflow

Methods included from UserGroups

#create_user_group, #delete_user_group, #join_user_group, #remove_user_from_user_group, #user_groups

Methods included from SubjectSets

#add_subjects_to_subject_set, #create_subject_set, #subject_set, #update_subject_set

Methods included from Subjects

#retire_subject, #subjects

Methods included from Projects

#create_aggregations_export, #create_classifications_export, #create_subjects_export, #create_workflow_contents_export, #create_workflows_export, #projects

Methods included from Me

#me

Constructor Details

#initialize(env: :production, auth: {}, public_key_path: nil) ⇒ Client

Returns a new instance of Client.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/panoptes/client.rb', line 36

def initialize(env: :production, auth: {}, public_key_path: nil)
  @env = env
  @auth = auth
  @public_key_path = public_key_path
  @panoptes = Panoptes::Endpoints::JsonApiEndpoint.new(
    auth: auth, url: panoptes_url, prefix: '/api'
  )
  @talk = Panoptes::Endpoints::JsonApiEndpoint.new(
    auth: auth, url: talk_url
  )
  @cellect = Panoptes::Endpoints::JsonEndpoint.new(
    url: panoptes_url, prefix: '/cellect'
  )
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



34
35
36
# File 'lib/panoptes/client.rb', line 34

def auth
  @auth
end

#cellectObject (readonly)

Returns the value of attribute cellect.



34
35
36
# File 'lib/panoptes/client.rb', line 34

def cellect
  @cellect
end

#envObject (readonly)

Returns the value of attribute env.



34
35
36
# File 'lib/panoptes/client.rb', line 34

def env
  @env
end

#panoptesObject (readonly)

Returns the value of attribute panoptes.



34
35
36
# File 'lib/panoptes/client.rb', line 34

def panoptes
  @panoptes
end

#talkObject (readonly)

Returns the value of attribute talk.



34
35
36
# File 'lib/panoptes/client.rb', line 34

def talk
  @talk
end

Instance Method Details

#current_userObject

Raises:



51
52
53
54
55
56
# File 'lib/panoptes/client.rb', line 51

def current_user
  raise NotLoggedIn unless @auth[:token]

  payload, = JWT.decode @auth[:token], jwt_signing_public_key, algorithm: 'RS512'
  payload.fetch('data')
end

#jwt_signing_public_keyObject



58
59
60
# File 'lib/panoptes/client.rb', line 58

def jwt_signing_public_key
  @jwt_signing_public_key ||= OpenSSL::PKey::RSA.new(File.read(@public_key_path))
end

#panoptes_urlObject



62
63
64
65
66
67
68
69
# File 'lib/panoptes/client.rb', line 62

def panoptes_url
  case env
  when :production, 'production'.freeze
    'https://panoptes.zooniverse.org'.freeze
  else
    'https://panoptes-staging.zooniverse.org'.freeze
  end
end

#talk_urlObject



71
72
73
74
75
76
77
78
# File 'lib/panoptes/client.rb', line 71

def talk_url
  case env
  when :production, 'production'.freeze
    'https://talk.zooniverse.org'.freeze
  else
    'https://talk-staging.zooniverse.org'.freeze
  end
end