Class: TranslateClient::API
- Inherits:
-
Object
- Object
- TranslateClient::API
- Defined in:
- lib/translate_client/api.rb
Defined Under Namespace
Classes: StartDeviceLoginResult, Viewer
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
writeonly
Temporarily set auth token while logging in, but before we have the viewer and can write their credentials to disk.
Instance Method Summary collapse
- #create_export(project_id:, locale:, format:) ⇒ Object
- #create_import(project_id:, locale:, format:, file:) ⇒ Object
- #download_export(export_id:) ⇒ Object
- #remote_locales(project_id:) ⇒ Object
- #request_login ⇒ Object
- #viewer ⇒ Object
Instance Attribute Details
#auth_token=(value) ⇒ Object (writeonly)
Temporarily set auth token while logging in, but before we have the viewer and can write their credentials to disk
9 10 11 |
# File 'lib/translate_client/api.rb', line 9 def auth_token=(value) @auth_token = value end |
Instance Method Details
#create_export(project_id:, locale:, format:) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/translate_client/api.rb', line 87 def create_export(project_id:, locale:, format:) query = <<~GRAPHQL mutation ($project_id: ID!, $locale: String!, $format: String!) { createExport(input: { projectId: $project_id, locale: $locale, format: $format }) { export { id } } } GRAPHQL result = execute(query, variables: { project_id:, locale:, format: }) result.data.createExport.export.id end |
#create_import(project_id:, locale:, format:, file:) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/translate_client/api.rb', line 61 def create_import(project_id:, locale:, format:, file:) query = <<~GRAPHQL mutation ($project_id: ID!, $locale: String!, $format: String!, $file: Upload!) { createImport(input: { projectId: $project_id, locale: $locale, format: $format, file: $file }) { import { id } } } GRAPHQL result = execute(query, variables: { project_id:, locale:, format:, file: }) result.data.createImport.import.id end |
#download_export(export_id:) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/translate_client/api.rb', line 111 def download_export(export_id:) query = <<~GRAPHQL query ($export_id: ID!) { export(id: $export_id) { file { url } } } GRAPHQL result = execute(query, variables: {export_id:}) file_url = result.data.export.file&.url return if file_url.nil? response = Faraday.get(file_url) Tempfile.new.tap do |tmpfile| tmpfile.write(response.body) tmpfile.rewind end end |
#remote_locales(project_id:) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/translate_client/api.rb', line 43 def remote_locales(project_id:) query = <<~GRAPHQL query($project_id: ID!) { project(id: $project_id) { locales { nodes { name } } } } GRAPHQL result = execute(query, variables: {project_id:}) result.data.project.locales.nodes.map(&:name) end |
#request_login ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/translate_client/api.rb', line 14 def request_login result = execute <<~GRAPHQL mutation { startDeviceLogin(input: {}) { authToken redirectUrl } } GRAPHQL StartDeviceLoginResult.new( auth_token: result.data.startDeviceLogin.authToken, redirect_url: result.data.startDeviceLogin.redirectUrl ) end |
#viewer ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/translate_client/api.rb', line 30 def viewer result = execute <<~GRAPHQL query { viewer { email } } GRAPHQL return nil if result.data.viewer.nil? Viewer.new(email: result.data.viewer.email) end |