smartcat_sdk 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8598d72622e424225419a6a3b292eaf0b5daa255
4
+ data.tar.gz: a4496d8cd25aa553a05b7eba1f9cc76abd6ee56c
5
+ SHA512:
6
+ metadata.gz: ac9cb9af9cd0b8f395b6a67ecae95db46c14b67c4a7913f14b39e3dd98e53853b37752c96fb3b34562ea4e608faf24cd52ac67e832e27d9a70123f06d17d6f6c
7
+ data.tar.gz: e489cc0f81b07414718c44d4dbc75bc8354ab43eacd06a8b92632bae4796f14e4973e1317d470f14053642ec95907ac7a0cbeb8303d50fbccf432a3d81e1d78f
@@ -0,0 +1,5 @@
1
+ speedups:
2
+ hash_merge_bang_vs_hash_brackets: true
3
+
4
+ exclude_paths:
5
+ - 'tmp/**/*'
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # RubyMine files
14
+ .idea/
15
+
16
+ # Result package
17
+ *.gem
18
+
19
+ # Ignore secret files
20
+ .pronto.yml
@@ -0,0 +1,7 @@
1
+ character_limit:
2
+ enabled: true
3
+ number: 72
4
+
5
+ summary_character_limit:
6
+ enabled: true
7
+ number: 50
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ Include:
3
+ - 'Rakefile'
4
+ - 'Gemfile'
5
+ Exclude:
6
+ - tmp/**/*
7
+
8
+ Documentation:
9
+ Enabled: false
10
+
11
+ Metrics/LineLength:
12
+ Max: 110
13
+ Exclude:
14
+ - 'Gemfile'
15
+ - 'smartcat_sdk.gemspec'
16
+
17
+ Metrics/MethodLength:
18
+ CountComments: false
19
+ Max: 10
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,19 @@
1
+
2
+ #### [Current]
3
+
4
+ ####
5
+ * [fce3015](../../commit/fce3015) - __(İsmail Akbudak)__ Implement document delete end-point
6
+ * [644959b](../../commit/644959b) - __(İsmail Akbudak)__ Implement project post end-points
7
+
8
+ - Cancel, restore and complete methods
9
+
10
+ * [6b1a713](../../commit/6b1a713) - __(İsmail Akbudak)__ Implement project document add end-point
11
+ * [d952903](../../commit/d952903) - __(İsmail Akbudak)__ Implement project target language add end-point
12
+ * [f5170e2](../../commit/f5170e2) - __(İsmail Akbudak)__ Implement project statistics build and get
13
+ * [9f4aeaf](../../commit/9f4aeaf) - __(İsmail Akbudak)__ Implement project update
14
+ * [609f44f](../../commit/609f44f) - __(İsmail Akbudak)__ Implement project destroy
15
+ * [c5a3f88](../../commit/c5a3f88) - __(İsmail Akbudak)__ Implement project create with files
16
+ * [4651bac](../../commit/4651bac) - __(İsmail Akbudak)__ Implement project detail fetch end-point
17
+ * [eb039a1](../../commit/eb039a1) - __(İsmail Akbudak)__ Fix pronto warnings
18
+ * [80ef842](../../commit/80ef842) - __(İsmail Akbudak)__ Update gemspec content
19
+ * [a572c86](../../commit/a572c86) - __(İsmail Akbudak)__ Initialize project
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ismail.akbudak@lab2023.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in smartcat_sdk.gemspec
6
+ gemspec
@@ -0,0 +1,139 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ smartcat_sdk (0.1.0)
5
+ mime-types (~> 3.0)
6
+ multi_json (~> 1.13, >= 1.13.1)
7
+ multipart-post (~> 2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.2)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ ast (2.4.0)
15
+ axiom-types (0.1.1)
16
+ descendants_tracker (~> 0.0.4)
17
+ ice_nine (~> 0.11.0)
18
+ thread_safe (~> 0.3, >= 0.3.1)
19
+ codeclimate-engine-rb (0.4.1)
20
+ virtus (~> 1.0)
21
+ coercible (1.0.0)
22
+ descendants_tracker (~> 0.0.1)
23
+ colorize (0.8.1)
24
+ descendants_tracker (0.0.4)
25
+ thread_safe (~> 0.3, >= 0.3.1)
26
+ diff-lcs (1.3)
27
+ equalizer (0.0.11)
28
+ erubis (2.7.0)
29
+ faraday (0.14.0)
30
+ multipart-post (>= 1.2, < 3)
31
+ fasterer (0.4.0)
32
+ colorize (~> 0.7)
33
+ ruby_parser (~> 3.9)
34
+ flay (2.10.0)
35
+ erubis (~> 2.7.0)
36
+ path_expander (~> 1.0)
37
+ ruby_parser (~> 3.0)
38
+ sexp_processor (~> 4.0)
39
+ gitlab (4.3.0)
40
+ httparty
41
+ terminal-table
42
+ httparty (0.15.6)
43
+ multi_xml (>= 0.5.2)
44
+ ice_nine (0.11.2)
45
+ mime-types (3.1)
46
+ mime-types-data (~> 3.2015)
47
+ mime-types-data (3.2016.0521)
48
+ multi_json (1.13.1)
49
+ multi_xml (0.6.0)
50
+ multipart-post (2.0.0)
51
+ octokit (4.8.0)
52
+ sawyer (~> 0.8.0, >= 0.5.3)
53
+ parallel (1.12.1)
54
+ parser (2.4.0.2)
55
+ ast (~> 2.3)
56
+ path_expander (1.0.2)
57
+ powerpack (0.1.1)
58
+ pronto (0.9.5)
59
+ gitlab (~> 4.0, >= 4.0.0)
60
+ httparty (>= 0.13.7)
61
+ octokit (~> 4.7, >= 4.7.0)
62
+ rainbow (~> 2.1)
63
+ rugged (~> 0.24, >= 0.23.0)
64
+ thor (~> 0.19.0)
65
+ pronto-fasterer (0.9.0)
66
+ fasterer (~> 0.3, >= 0.3.0)
67
+ pronto (~> 0.9.0)
68
+ pronto-flay (0.9.0)
69
+ flay (~> 2.8)
70
+ pronto (~> 0.9.0)
71
+ pronto-reek (0.9.0)
72
+ pronto (~> 0.9.0)
73
+ reek (~> 4.2)
74
+ pronto-rubocop (0.9.0)
75
+ pronto (~> 0.9.0)
76
+ rubocop (~> 0.38, >= 0.35.0)
77
+ public_suffix (3.0.1)
78
+ rainbow (2.2.2)
79
+ rake
80
+ rake (10.4.2)
81
+ reek (4.7.3)
82
+ codeclimate-engine-rb (~> 0.4.0)
83
+ parser (>= 2.4.0.0, < 2.5)
84
+ rainbow (~> 2.0)
85
+ rspec (3.5.0)
86
+ rspec-core (~> 3.5.0)
87
+ rspec-expectations (~> 3.5.0)
88
+ rspec-mocks (~> 3.5.0)
89
+ rspec-core (3.5.4)
90
+ rspec-support (~> 3.5.0)
91
+ rspec-expectations (3.5.0)
92
+ diff-lcs (>= 1.2.0, < 2.0)
93
+ rspec-support (~> 3.5.0)
94
+ rspec-mocks (3.5.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.5.0)
97
+ rspec-support (3.5.0)
98
+ rubocop (0.52.1)
99
+ parallel (~> 1.10)
100
+ parser (>= 2.4.0.2, < 3.0)
101
+ powerpack (~> 0.1)
102
+ rainbow (>= 2.2.2, < 4.0)
103
+ ruby-progressbar (~> 1.7)
104
+ unicode-display_width (~> 1.0, >= 1.0.1)
105
+ ruby-progressbar (1.9.0)
106
+ ruby_parser (3.10.1)
107
+ sexp_processor (~> 4.9)
108
+ rugged (0.26.0)
109
+ sawyer (0.8.1)
110
+ addressable (>= 2.3.5, < 2.6)
111
+ faraday (~> 0.8, < 1.0)
112
+ sexp_processor (4.10.0)
113
+ terminal-table (1.8.0)
114
+ unicode-display_width (~> 1.1, >= 1.1.1)
115
+ thor (0.19.4)
116
+ thread_safe (0.3.6)
117
+ unicode-display_width (1.3.0)
118
+ virtus (1.0.5)
119
+ axiom-types (~> 0.1)
120
+ coercible (~> 1.0)
121
+ descendants_tracker (~> 0.0, >= 0.0.3)
122
+ equalizer (~> 0.0, >= 0.0.9)
123
+
124
+ PLATFORMS
125
+ ruby
126
+
127
+ DEPENDENCIES
128
+ bundler (~> 1.16)
129
+ pronto (~> 0.9.5)
130
+ pronto-fasterer (~> 0.9.0)
131
+ pronto-flay (~> 0.9.0)
132
+ pronto-reek (~> 0.9.0)
133
+ pronto-rubocop (~> 0.9.0)
134
+ rake (~> 10.0)
135
+ rspec (~> 3.5)
136
+ smartcat_sdk!
137
+
138
+ BUNDLED WITH
139
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 İsmail Akbudak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # SmartcatSDK
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/smartcat_sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'smartcat_sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install smartcat_sdk
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/smartcat_sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the SmartcatSDK project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/smartcat_sdk/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1 @@
1
+ v1.0.1
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'smartcat_sdk'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
File without changes
@@ -0,0 +1,21 @@
1
+ "lib/smartcat_sdk/rest":
2
+ InstanceVariableAssumption:
3
+ enabled: false
4
+ TooManyInstanceVariables:
5
+ max_instance_variables: 6
6
+
7
+ IrresponsibleModule:
8
+ enabled: false
9
+
10
+ DuplicateMethodCall:
11
+ enabled: false
12
+
13
+ FeatureEnvy:
14
+ enabled: false
15
+
16
+ TooManyStatements:
17
+ enabled: true
18
+ max_statements: 6
19
+
20
+ LongParameterList:
21
+ max_params: 4
@@ -0,0 +1,77 @@
1
+ require 'smartcat_sdk'
2
+
3
+ ACCOUNT_ID = 'ACCOUNT_ID'.freeze
4
+ API_KEY = 'API_KEY'.freeze
5
+
6
+ # -------------------------------------------------------------
7
+ # -------------------------------------------------------------
8
+ # Project API end-point
9
+ # -------------------------------------------------------------
10
+ # -------------------------------------------------------------
11
+ project = SmartcatSDK::REST::Project.new(ACCOUNT_ID, API_KEY)
12
+ # Get project details
13
+ PROJECT_ID = 'EXAMPLE_PROJECT_ID'.freeze
14
+ puts project.get(PROJECT_ID)
15
+
16
+ # Update project
17
+ model = {
18
+ 'name' => 'Updated name',
19
+ 'description' => 'Updated description',
20
+ 'externalTag' => 'id'
21
+ }
22
+ puts project.update(PROJECT_ID, model)
23
+
24
+ # Delete project
25
+ puts project.delete(PROJECT_ID)
26
+
27
+ # Create project without file
28
+ model = {
29
+ 'name' => 'Test',
30
+ 'description' => 'Test',
31
+ 'sourceLanguage' => 'tr',
32
+ 'targetLanguages' => %w[en],
33
+ 'workflowStages' => [
34
+ 'translation'
35
+ ],
36
+ 'assignToVendor' => false
37
+ }
38
+ puts project.create(model)
39
+
40
+ # Create project with files
41
+ puts project.create(model, files: %w[files/Test.txt files/Test-2.txt])
42
+
43
+ # Get project statistics
44
+ puts project.statistics(PROJECT_ID)
45
+
46
+ # Post project statistics build
47
+ puts project.statistics_build(PROJECT_ID)
48
+
49
+ # Post add target language to project
50
+ puts project.add_language(PROJECT_ID, 'de')
51
+ puts project.add_language(PROJECT_ID, 'it')
52
+
53
+ # Post add document to project
54
+ puts project.add_document(
55
+ PROJECT_ID,
56
+ files_model: [{ externalId: 'test1' }, { externalId: 'test2' }],
57
+ files: %w[files/Test.txt files/Test-2.txt]
58
+ )
59
+
60
+ # Post project cancel
61
+ puts project.cancel(PROJECT_ID)
62
+
63
+ # Post project restore
64
+ puts project.restore(PROJECT_ID)
65
+
66
+ # Post project complete
67
+ puts project.complete(PROJECT_ID)
68
+
69
+ # -------------------------------------------------------------
70
+ # -------------------------------------------------------------
71
+ # Document API end-point
72
+ # -------------------------------------------------------------
73
+ # -------------------------------------------------------------
74
+ document = SmartcatSDK::REST::Document.new(ACCOUNT_ID, API_KEY)
75
+ # Delete documents
76
+ DOCUMENT_IDS = %w[2048153_9 2048153_7].freeze
77
+ puts document.delete(DOCUMENT_IDS)
@@ -0,0 +1 @@
1
+ test test test test test test
@@ -0,0 +1 @@
1
+ test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'json'
4
+
5
+ # Our multipart post lib
6
+ require 'net/http/post/multipart'
7
+
8
+ # JSON parser
9
+ require 'multi_json'
10
+
11
+ # File format decider
12
+ require 'mime/types'
13
+
14
+ # Smartcat files
15
+ require 'smartcat_sdk/version' unless defined?(SmartcatSDK::VERSION)
16
+ require 'smartcat_sdk/util/client_config'
17
+ require 'smartcat_sdk/util/project'
18
+ require 'smartcat_sdk/util/request'
19
+ require 'smartcat_sdk/rest/errors'
20
+ require 'smartcat_sdk/rest/project'
21
+ require 'smartcat_sdk/rest/document'
22
+
23
+ module SmartcatSDK
24
+ # Your code goes here...
25
+ end
@@ -0,0 +1,117 @@
1
+ module SmartcatSDK
2
+ module REST
3
+ class BaseRequest
4
+ def initialize(*args)
5
+ options = args.last.is_a?(Hash) ? args.pop : {}
6
+ @config = SmartcatSDK::Util::ClientConfig.new options
7
+ @user = args[0] || nil
8
+ @password = args[1] || nil
9
+ raise ArgumentError, 'Account ID is required' unless @user
10
+ raise ArgumentError, 'API key is required' unless @password
11
+ set_up_connection
12
+ end
13
+
14
+ protected
15
+
16
+ ##
17
+ # Prepare http request
18
+ # :reek:TooManyStatements { enabled: false }
19
+ def prepare_request(method, path, params: {}, headers: {})
20
+ request_path = @config.host
21
+ request_path += "/api/integration/v1/#{path}"
22
+ uri = URI.parse(request_path)
23
+ uri.query = URI.encode_www_form(params) if %w[get delete].include?(method.to_s)
24
+ request = SmartcatSDK::Util::Request.prepare(headers, method, params, uri)
25
+ request.basic_auth(@user, @password)
26
+ connect_and_send(request)
27
+ end
28
+
29
+ private
30
+
31
+ ##
32
+ # Set up and cache a Net::HTTP object to use when making requests.
33
+ # rubocop:disable Metrics/AbcSize
34
+ # rubocop:disable Metrics/MethodLength
35
+ # :reek:TooManyStatements { enabled: false }
36
+ def set_up_connection
37
+ uri = URI.parse(@config.host)
38
+ @http = Net::HTTP.new(
39
+ uri.host,
40
+ uri.port,
41
+ @config.proxy_addr,
42
+ @config.proxy_port,
43
+ @config.proxy_user,
44
+ @config.proxy_pass
45
+ )
46
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
47
+ @http.use_ssl = @config.use_ssl
48
+ if @config.ssl_verify_peer
49
+ @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
50
+ @http.ca_file = @config.ssl_ca_file
51
+ else
52
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
53
+ end
54
+ @http.open_timeout = @config.timeout
55
+ @http.read_timeout = @config.timeout
56
+ end
57
+ # rubocop:enable Metrics/AbcSize
58
+
59
+ ##
60
+ # Send an HTTP request using the cached <tt>@http</tt> object and
61
+ # return the JSON response body parsed into a hash. Also save the raw
62
+ # Net::HTTP::Request and Net::HTTP::Response objects as
63
+ # <tt>@last_request</tt> and <tt>@last_response</tt> to allow for
64
+ # inspection later.
65
+ # :reek:TooManyStatements { enabled: false }
66
+ def connect_and_send(request, type: :json)
67
+ @last_request = request
68
+ retries_left = @config.retry_limit
69
+ begin
70
+ response = @http.request request
71
+ @last_response = response
72
+ raise SmartcatSDK::REST::ServerError if response.is_a?(Net::HTTPServerError)
73
+ rescue StandardError => _error
74
+ raise if request.class == Net::HTTP::Post
75
+ raise if retries_left <= 0
76
+ retries_left -= 1
77
+ retry
78
+ end
79
+ Builder.handle(type, response)
80
+ end
81
+ # rubocop:enable Metrics/MethodLength
82
+
83
+ class Builder
84
+ # rubocop:disable Metrics/MethodLength
85
+ # rubocop:disable Metrics/AbcSize
86
+ def self.handle(type, response)
87
+ if response.is_a?(Net::HTTPClientError)
88
+ raise SmartcatSDK::REST::RequestError.new(response.body, response.code)
89
+ end
90
+ if response.body && !response.body.empty?
91
+ builder_class = Builder.const_get(type.to_s.capitalize)
92
+ builder_class.result(response.body)
93
+ elsif response.is_a?(Net::HTTPBadRequest)
94
+ {
95
+ message: 'Bad request',
96
+ code: 400
97
+ }
98
+ end
99
+ end
100
+ # rubocop:enable Metrics/MethodLength
101
+ # rubocop:enable Metrics/AbcSize
102
+
103
+ class Body
104
+ def self.result(body)
105
+ body
106
+ end
107
+ end
108
+
109
+ class Json
110
+ def self.result(body)
111
+ MultiJson.load(body)
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,16 @@
1
+ require 'smartcat_sdk/rest/base_request'
2
+
3
+ module SmartcatSDK
4
+ module REST
5
+ class Document < BaseRequest
6
+ def initialize(*args)
7
+ super(*args)
8
+ @resource = 'document'
9
+ end
10
+
11
+ def delete(document_ids = [])
12
+ prepare_request(:delete, @resource, params: { documentIds: document_ids })
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ module SmartcatSDK
2
+ module REST
3
+ class ServerError < StandardError; end
4
+
5
+ class RequestError < StandardError
6
+ attr_reader :code
7
+
8
+ def initialize(message, code = nil)
9
+ super message
10
+ @code = code
11
+ end
12
+ end
13
+
14
+ class SDKError < StandardError
15
+ attr_reader :code
16
+
17
+ def initialize(message, code = nil)
18
+ super message
19
+ @code = code
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,75 @@
1
+ require 'smartcat_sdk/rest/base_request'
2
+
3
+ module SmartcatSDK
4
+ module REST
5
+ class Project < BaseRequest
6
+ def initialize(*args)
7
+ super(*args)
8
+ @resource = 'project'
9
+ end
10
+
11
+ # @param [Hash] project_model
12
+ # @param [Array] files file directory paths
13
+ def create(project_model, files: [])
14
+ prepare_request(
15
+ :post_multipart,
16
+ "#{@resource}/create",
17
+ params: SmartcatSDK::Util::Project.params(project_model, files),
18
+ headers: SmartcatSDK::Util::Project.model_headers
19
+ )
20
+ end
21
+
22
+ def get(project_id)
23
+ prepare_request(:get, "#{@resource}/#{project_id}")
24
+ end
25
+
26
+ def update(project_id, project_model)
27
+ prepare_request(
28
+ :put,
29
+ "#{@resource}/#{project_id}",
30
+ params: project_model
31
+ )
32
+ end
33
+
34
+ def delete(project_id)
35
+ prepare_request(:delete, "#{@resource}/#{project_id}")
36
+ end
37
+
38
+ def statistics(project_id)
39
+ prepare_request(:get, "#{@resource}/#{project_id}/statistics")
40
+ end
41
+
42
+ def statistics_build(project_id)
43
+ prepare_request(:post, "#{@resource}/#{project_id}/statistics/build")
44
+ end
45
+
46
+ def add_language(project_id, target_language)
47
+ prepare_request(
48
+ :post,
49
+ "#{@resource}/language?projectId=#{project_id}&targetLanguage=#{target_language}"
50
+ )
51
+ end
52
+
53
+ def add_document(project_id, files: [], files_model: [])
54
+ prepare_request(
55
+ :post_multipart,
56
+ "#{@resource}/document?projectId=#{project_id}",
57
+ params: SmartcatSDK::Util::Project.params(files_model, files),
58
+ headers: SmartcatSDK::Util::Project.model_headers
59
+ )
60
+ end
61
+
62
+ def cancel(project_id)
63
+ prepare_request(:post, "#{@resource}/cancel?projectId=#{project_id}")
64
+ end
65
+
66
+ def restore(project_id)
67
+ prepare_request(:post, "#{@resource}/restore?projectId=#{project_id}")
68
+ end
69
+
70
+ def complete(project_id)
71
+ prepare_request(:post, "#{@resource}/complete?projectId=#{project_id}")
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,29 @@
1
+ module SmartcatSDK
2
+ module Util
3
+ class ClientConfig
4
+ DEFAULTS = {
5
+ host: 'https://smartcat.ai',
6
+ port: 80,
7
+ use_ssl: true,
8
+ ssl_verify_peer: false,
9
+ ssl_ca_file: File.dirname(__FILE__) + '/../../../conf/cert.pem',
10
+ timeout: 30,
11
+ proxy_addr: nil,
12
+ proxy_port: nil,
13
+ proxy_user: nil,
14
+ proxy_pass: nil,
15
+ retry_limit: 2
16
+ }.freeze
17
+
18
+ DEFAULTS.each_key do |attribute|
19
+ attr_accessor attribute
20
+ end
21
+
22
+ def initialize(opts = {})
23
+ DEFAULTS.each do |attribute, value|
24
+ send("#{attribute}=".to_sym, opts.fetch(attribute) { value })
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ module SmartcatSDK
2
+ module Util
3
+ module Project
4
+ MODEL_KEY = 'model'.freeze
5
+
6
+ class << self
7
+ def params(project_model, files)
8
+ params = {
9
+ SmartcatSDK::Util::Project::MODEL_KEY => JSON.generate(project_model)
10
+ }
11
+ prepare_files(files, params)
12
+ params
13
+ end
14
+
15
+ def model_headers
16
+ {
17
+ parts: {
18
+ MODEL_KEY => {
19
+ 'Content-Type' => 'application/json'
20
+ }
21
+ }
22
+ }
23
+ end
24
+
25
+ private
26
+
27
+ # :reek:TooManyStatements { enabled: false }
28
+ def prepare_files(files, params)
29
+ index = 0
30
+ files.each do |path|
31
+ file_name = File.basename(path)
32
+ file = File.new(path)
33
+ content_type = MIME::Types.type_for(file.path).first.to_s
34
+ params["project_file#{index}"] = UploadIO.new(file, content_type, file_name)
35
+ index += 1
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ module SmartcatSDK
2
+ module Util
3
+ module Request
4
+ RUBY_INFO = "(#{RUBY_ENGINE}/#{RUBY_PLATFORM} #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL})".freeze
5
+ HTTP_HEADERS = {
6
+ 'Accept' => 'application/json',
7
+ 'Accept-Charset' => 'utf-8',
8
+ 'User-Agent' => "smartcat_sdk/#{SmartcatSDK::VERSION} #{RUBY_INFO}"
9
+ }.freeze
10
+
11
+ class << self
12
+ def prepare(headers, method, params, uri)
13
+ if method == :post_multipart
14
+ return Net::HTTP::Post::Multipart.new(uri, params, HTTP_HEADERS.merge(headers))
15
+ end
16
+ method_class = Net::HTTP.const_get method.to_s.capitalize
17
+ request = method_class.new(uri, headers)
18
+ if %w[post put].include?(method.to_s)
19
+ request.content_type = 'application/json'
20
+ request.body = JSON.dump(params)
21
+ end
22
+ request
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module SmartcatSDK
2
+ VERSION = '1.0.1'.freeze
3
+ end
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smartcat_sdk/version'
5
+ require 'date'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'smartcat_sdk'
9
+ spec.version = SmartcatSDK::VERSION
10
+ spec.authors = ['İsmail Akbudak']
11
+ spec.email = ['ismail.akbudak@lab2023.com']
12
+ spec.summary = 'SmartCat Ruby SDK.'
13
+ spec.description = 'SmartCat API SDK for ruby & ruby on rails.'
14
+ spec.homepage = 'https://github.com/ismailakbudak/smartcat_ruby_sdk'
15
+ spec.license = 'MIT'
16
+ spec.date = Date.today.strftime('%Y-%m-%d')
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+ spec.add_runtime_dependency 'multi_json', '~> 1.13', '>= 1.13.1'
24
+ spec.add_runtime_dependency 'multipart-post', '~> 2.0'
25
+ spec.add_dependency 'mime-types', '~> 3.0'
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'pronto', '~> 0.9.5'
28
+ spec.add_development_dependency 'pronto-fasterer', '~> 0.9.0'
29
+ spec.add_development_dependency 'pronto-flay', '~> 0.9.0'
30
+ spec.add_development_dependency 'pronto-reek', '~> 0.9.0'
31
+ spec.add_development_dependency 'pronto-rubocop', '~> 0.9.0'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.5'
34
+ end
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartcat_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - İsmail Akbudak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.13.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.13'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.13.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: multipart-post
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: mime-types
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.16'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.16'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pronto
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.9.5
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.9.5
89
+ - !ruby/object:Gem::Dependency
90
+ name: pronto-fasterer
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.9.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: pronto-flay
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.9.0
117
+ - !ruby/object:Gem::Dependency
118
+ name: pronto-reek
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.9.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.9.0
131
+ - !ruby/object:Gem::Dependency
132
+ name: pronto-rubocop
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.9.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.9.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: rake
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '10.0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '10.0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: rspec
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '3.5'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.5'
173
+ description: SmartCat API SDK for ruby & ruby on rails.
174
+ email:
175
+ - ismail.akbudak@lab2023.com
176
+ executables: []
177
+ extensions: []
178
+ extra_rdoc_files: []
179
+ files:
180
+ - ".fasterer.yml"
181
+ - ".gitignore"
182
+ - ".poper.yml"
183
+ - ".rspec"
184
+ - ".rubocop.yml"
185
+ - ".travis.yml"
186
+ - CHANGELOG.md
187
+ - CODE_OF_CONDUCT.md
188
+ - Gemfile
189
+ - Gemfile.lock
190
+ - LICENSE.txt
191
+ - README.md
192
+ - Rakefile
193
+ - VERSION.txt
194
+ - bin/console
195
+ - bin/setup
196
+ - conf/cert.pem
197
+ - config.reek
198
+ - examples/example.rb
199
+ - examples/files/Test-2.txt
200
+ - examples/files/Test.txt
201
+ - lib/smartcat_sdk.rb
202
+ - lib/smartcat_sdk/rest/base_request.rb
203
+ - lib/smartcat_sdk/rest/document.rb
204
+ - lib/smartcat_sdk/rest/errors.rb
205
+ - lib/smartcat_sdk/rest/project.rb
206
+ - lib/smartcat_sdk/util/client_config.rb
207
+ - lib/smartcat_sdk/util/project.rb
208
+ - lib/smartcat_sdk/util/request.rb
209
+ - lib/smartcat_sdk/version.rb
210
+ - smartcat_sdk.gemspec
211
+ homepage: https://github.com/ismailakbudak/smartcat_ruby_sdk
212
+ licenses:
213
+ - MIT
214
+ metadata: {}
215
+ post_install_message:
216
+ rdoc_options: []
217
+ require_paths:
218
+ - lib
219
+ required_ruby_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ requirements: []
230
+ rubyforge_project:
231
+ rubygems_version: 2.5.2.1
232
+ signing_key:
233
+ specification_version: 4
234
+ summary: SmartCat Ruby SDK.
235
+ test_files: []