Skip to content

Commit f1445eb

Browse files
Merge branch 'master' into special-characters-url
2 parents 51e1f23 + 62dd4e8 commit f1445eb

File tree

19 files changed

+526
-153
lines changed

19 files changed

+526
-153
lines changed

.github/workflows/test.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
12-
- name: Set up Ruby 2.6
13-
uses: actions/setup-ruby@v1
14-
with:
15-
ruby-version: 2.6.x
16-
- name: Build and test with Rake
17-
run: |
18-
gem install bundler
19-
bundle install --jobs 4 --retry 3
20-
bundle exec rake
11+
- uses: actions/checkout@v2
12+
- name: Set up Ruby 2.6
13+
uses: actions/setup-ruby@v1
14+
with:
15+
ruby-version: 2.6.x
16+
- name: Build and test with Rake
17+
run: |
18+
gem install bundler
19+
bundle install --jobs 4 --retry 3
20+
bundle exec rake
21+
# - name: Upload code coverage reports to codecov
22+
# uses: codecov/codecov-action@v1
23+
# with:
24+
# token: 58fd7bff-e88e-4f23-b940-811b12f20dcf # not required for public repos
25+
# # file: ./coverage.xml # optional
26+
# # files: ./coverage1.xml,./coverage2.xml # optional
27+
# # flags: unittests # optional
28+
# # name: codecov-umbrella # optional
29+
# # fail_ci_if_error: true # optional (default = false)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.bundle/
22
log/*.log
33
pkg/
4+
coverage/
45
test/dummy/db/*.sqlite3
56
test/dummy/db/*.sqlite3-journal
67
test/dummy/db/*.sqlite3-*

DEVEMOPMENT.md renamed to DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ bundle exec rake
1717
**3. To build gem**
1818
```shell
1919
gem build imagekit.gemspec
20-
```
20+
```

Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ gemspec
1717
gem "minitest", "~> 5.0"
1818
# gem "rake", "~> 12.0"
1919
# gem "rest-client", "~>2.1"
20-
gem "rspec"
20+
gem "rspec"
21+
22+
gem 'codecov', require: false, group: 'test'
23+
gem 'webmock', require: false, group: 'test'

README.md

Lines changed: 99 additions & 95 deletions
Large diffs are not rendered by default.

lib/imagekit/constants/errors.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@
6969
'help': "Please pass two pHash values",}
7070
UNEQUAL_STRING_LENGTH = {'message': "Unequal pHash string length",
7171
'help': "For distance calculation, the two pHash strings must have equal length",}
72+
73+
MISSING_PRIVATE_KEY = "ImageKit private key missing"
74+
75+
MISSING_PUBLIC_KEY = "ImageKit public key missing"
76+
77+
MISSING_URL_ENDPOINT = "ImageKit URL Endpoint missing. Default URL Endpoint: https://ik.imagekit.io/<YOUR_IMAGEKIT_ID>/"

lib/imagekit/constants/supported_transformation.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@
1111
'format': "f",
1212
'radius': "r",
1313
'background': "bg",
14-
'border': "bo",
14+
'border': "b",
1515
'rotation': "rt",
1616
'blur': "bl",
1717
'named': "n",
1818
'overlay_image': "oi",
19+
'overlay_image_trim': "oit",
20+
'overlay_image_cropping': "oic",
21+
'overlay_image_quality': "oiq",
22+
'overlay_image_DPR': "oidpr",
23+
'overlay_image_border': "oib",
24+
'overlay_image_background': "oibg",
25+
'overlay_image_aspect_ratio': "oiar",
1926
'overlay_x': "ox",
2027
'overlay_y': "oy",
2128
'overlay_focus': "ofo",
@@ -24,11 +31,17 @@
2431
'overlay_text': "ot",
2532
'overlay_text_font_size': "ots",
2633
'overlay_text_font_family': "otf",
34+
'overlay_text_encoded': "ote",
2735
'overlay_text_color': "otc",
36+
'overlay_text_width': "otw",
37+
'overlay_text_background': "otbg",
38+
'overlay_text_padding': "otp",
39+
'overlay_text_inner_alignment': "otia",
40+
'overlay_text_transparency': "oa",
2841
'overlay_alpha': "oa",
42+
'overlay_radius': "or",
2943
'overlay_text_typography': "ott",
3044
'overlay_background': "obg",
31-
'overlay_image_trim': "oit",
3245
'progressive': "pr",
3346
'lossless': "lo",
3447
'trim': "t",

lib/imagekit/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ def validate_upload_options(options)
130130
end
131131
request_formatter(options)
132132
end
133-
end
133+
end

lib/imagekit/imagekit.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ class ImageKitClient
1616
attr_reader :file
1717

1818
def initialize(private_key, public_key, url_endpoint, transformation_pos = nil, options = nil)
19+
20+
unless(private_key.is_a?(String) && private_key.to_s.strip.length != 0)
21+
raise ArgumentError, MISSING_PRIVATE_KEY
22+
end
23+
unless(public_key.is_a?(String) && public_key.to_s.strip.length != 0)
24+
raise ArgumentError, MISSING_PUBLIC_KEY
25+
end
26+
unless(url_endpoint.is_a?(String) && url_endpoint.to_s.strip.length != 0)
27+
raise ArgumentError, MISSING_URL_ENDPOINT
28+
end
29+
1930
@private_key = private_key
2031
@public_key = public_key
2132
@url_endpoint = url_endpoint
@@ -92,8 +103,7 @@ def get_remote_file_url_metadata(remote_file_url = "")
92103
def phash_distance(first, second)
93104
# Get hamming distance between two phash(image hash) to check
94105
# similarity between images
95-
96-
unless first && second
106+
if first.to_s.strip == "" || second.to_s.strip == ""
97107
raise ArgumentError, Error::MISSING_PHASH_VALUE
98108
end
99109
hamming_distance(first, second)
@@ -104,5 +114,4 @@ def get_authentication_parameters(token = nil, expire = nil)
104114
get_authenticated_params(token, expire, @ik_req.private_key)
105115
end
106116
end
107-
end
108-
117+
end

lib/imagekit/resource.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ def request(method, url, headers = nil, payload = nil)
3838
headers: headers,
3939
payload: payload).execute
4040

41-
42-
if resp.code == 404
43-
raise RestClient::ExceptionWithResponse
44-
elsif (resp.code >= 200) && (resp.code < 204)
45-
response[:response] = JSON.parse(resp.body.to_s)
41+
if (resp.code >= 200) && (resp.code < 204)
42+
if (resp.headers[:content_type].include? "application/json")
43+
response[:response] = JSON.parse(resp.body.to_s)
44+
else
45+
raise =RestClient::ExceptionWithResponse
46+
end
4647
elsif resp.code == 204
4748
response[:response] = {'success': true}
4849
end

0 commit comments

Comments
 (0)