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 = " mutation ($project_id: ID!, $locale: String!, $format: String!) {\n createExport(input: {\n projectId: $project_id,\n locale: $locale,\n format: $format\n }) {\n export {\n id\n }\n }\n }\n GRAPHQL\n\n result = execute(query, variables: {\n project_id:,\n locale:,\n format:\n })\n\n result.data.createExport.export.id\nend\n" |
#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 = " mutation ($project_id: ID!, $locale: String!, $format: String!, $file: Upload!) {\n createImport(input: {\n projectId: $project_id,\n locale: $locale,\n format: $format,\n file: $file\n }) {\n import {\n id\n }\n }\n }\n GRAPHQL\n\n result = execute(query, variables: {\n project_id:,\n locale:,\n format:,\n file:\n })\n\n result.data.createImport.import.id\nend\n" |
#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 = " query ($export_id: ID!) {\n export(id: $export_id) {\n file {\n url\n }\n }\n }\n GRAPHQL\n\n result = execute(query, variables: {export_id:})\n file_url = result.data.export.file&.url\n\n return if file_url.nil?\n\n response = Faraday.get(file_url)\n\n Tempfile.new.tap do |tmpfile|\n tmpfile.write(response.body)\n tmpfile.rewind\n end\nend\n" |
#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 = " query($project_id: ID!) {\n project(id: $project_id) {\n locales {\n nodes {\n name\n }\n }\n }\n }\n GRAPHQL\n\n result = execute(query, variables: {project_id:})\n\n result.data.project.locales.nodes.map(&:name)\nend\n" |
#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 " mutation {\n startDeviceLogin(input: {}) {\n authToken\n redirectUrl\n }\n }\n GRAPHQL\n\n StartDeviceLoginResult.new(\n auth_token: result.data.startDeviceLogin.authToken,\n redirect_url: result.data.startDeviceLogin.redirectUrl\n )\nend\n" |
#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 " query {\n viewer {\n email\n }\n }\n GRAPHQL\n return nil if result.data.viewer.nil?\n\n Viewer.new(email: result.data.viewer.email)\nend\n" |