envato 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +46 -0
  3. data/.rspec +5 -0
  4. data/.rubocop.yml +142 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +84 -0
  7. data/LICENSE +7 -0
  8. data/README.md +152 -0
  9. data/Rakefile +16 -0
  10. data/envato.gemspec +34 -0
  11. data/lib/envato/client.rb +55 -0
  12. data/lib/envato/collection.rb +25 -0
  13. data/lib/envato/error.rb +6 -0
  14. data/lib/envato/object.rb +25 -0
  15. data/lib/envato/objects/types.rb +19 -0
  16. data/lib/envato/resource.rb +59 -0
  17. data/lib/envato/resources/bookmarks.rb +34 -0
  18. data/lib/envato/resources/item.rb +43 -0
  19. data/lib/envato/resources/market.rb +131 -0
  20. data/lib/envato/resources/markets.rb +42 -0
  21. data/lib/envato/resources/search.rb +21 -0
  22. data/lib/envato/resources/user.rb +60 -0
  23. data/lib/envato/resources/users.rb +10 -0
  24. data/lib/envato/version.rb +8 -0
  25. data/lib/envato.rb +39 -0
  26. data/spec/bookmarks_spec.rb +15 -0
  27. data/spec/envato_spec.rb +26 -0
  28. data/spec/item_spec.rb +90 -0
  29. data/spec/market_spec.rb +100 -0
  30. data/spec/markets_spec.rb +14 -0
  31. data/spec/search_spec.rb +41 -0
  32. data/spec/spec_helper.rb +51 -0
  33. data/spec/user_spec.rb +118 -0
  34. data/spec/users_spec.rb +15 -0
  35. data/spec/vcr/bookmarks_list.yml +87 -0
  36. data/spec/vcr/item_info.yml +88 -0
  37. data/spec/vcr/item_list_purchases.yml +87 -0
  38. data/spec/vcr/item_prices.yml +86 -0
  39. data/spec/vcr/item_purchases.yml +87 -0
  40. data/spec/vcr/item_version.yml +87 -0
  41. data/spec/vcr/market_categories_graphicriver.yml +147 -0
  42. data/spec/vcr/market_categories_themeforest.yml +201 -0
  43. data/spec/vcr/market_features_graphicriver.yml +97 -0
  44. data/spec/vcr/market_features_themeforest.yml +93 -0
  45. data/spec/vcr/market_new_files.yml +86 -0
  46. data/spec/vcr/market_new_files_graphicriver_graphics.yml +115 -0
  47. data/spec/vcr/market_popular_items_themeforest.yml +86 -0
  48. data/spec/vcr/market_total_items.yml +85 -0
  49. data/spec/vcr/search_comments.yml +88 -0
  50. data/spec/vcr/search_item.yml +88 -0
  51. data/spec/vcr/search_more_like_this.yml +88 -0
  52. data/spec/vcr/user_account.yml +86 -0
  53. data/spec/vcr/user_badges.yml +98 -0
  54. data/spec/vcr/user_badges_not_exists.yml +83 -0
  55. data/spec/vcr/user_collection.yml +88 -0
  56. data/spec/vcr/user_collections.yml +90 -0
  57. data/spec/vcr/user_email.yml +85 -0
  58. data/spec/vcr/user_items.yml +86 -0
  59. data/spec/vcr/user_name.yml +85 -0
  60. data/spec/vcr/user_statement.yml +111 -0
  61. data/spec/vcr/users_total.yml +85 -0
  62. metadata +147 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0803d16509a393c20d289dad31220711faccadd9cc5b03821d0c6a24f297fa33'
4
- data.tar.gz: 7439e670daa5fb74d6c96809ea72772c0acec9acb90d5dff797f6d360e2e1374
3
+ metadata.gz: d218714f8633fe293e92eae29201a5f3e43713237f167ccca14786eccd2a6441
4
+ data.tar.gz: 7edab5418e1e89d7077e56e1b9919c26e3981c0108b0c532aacf3be9ab8c3715
5
5
  SHA512:
6
- metadata.gz: 5f4b0c6b832f601d7e4bc5be400b3382a31e1be402119f12794ec8de37f57fd173edc8566175a3a6e25886d039b3481c64dd51f2efc30c063afa7c033f866660
7
- data.tar.gz: 436335c438e3842e1c5b3930de468669496a4a28a5a7d17444d5f5fd8ad161c6f9b2ffabab1617fbce790de2c2ef7b4064e1deb8e4b881f90f3b395640498b58
6
+ metadata.gz: 8eadf73abe33a300e4d20e3d53fac5ca1b8fa30cac3561c0676a489e265afaa5991a26f0afb53fcce5b7de3623f3455cd8d747717bd3074118cdfd87fb7c50cb
7
+ data.tar.gz: 61fdb4c1bac7b49ccb01fccdc6f2f562a37f93ee7c4952bdcd63752c97988a8f72fc4f8133afb90a7177022372a51b3beb31427d40d7a0a9081e9f02c25367c0
data/.gitignore ADDED
@@ -0,0 +1,46 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ ## macos
37
+ .DS_Store
38
+ dev
39
+
40
+ # TODO: remove from ignore list
41
+ api_endpoints.json
42
+ api.sh
43
+
44
+ fixtures
45
+ .rspec_status
46
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --tty
2
+ --color
3
+ --format documentation # progress
4
+ --backtrace
5
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,142 @@
1
+ ---
2
+ AllCops:
3
+ NewCops: disable # TODO: change to enable after refactoring
4
+
5
+ # Commonly used screens these days easily fit more than 80 characters.
6
+ Layout/LineLength:
7
+ Max: 120
8
+
9
+ # Too short methods lead to extraction of single-use methods, which can make
10
+ # the code easier to read (by naming things), but can also clutter the class
11
+ Metrics/MethodLength:
12
+ Max: 20
13
+
14
+ # The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
15
+ Metrics/ClassLength:
16
+ Max: 1500
17
+
18
+ # No space makes the method definition shorter and differentiates
19
+ # from a regular assignment.
20
+ Layout/SpaceAroundEqualsInParameterDefault:
21
+ EnforcedStyle: no_space
22
+
23
+ # Single quotes being faster is hardly measurable and only affects parse time.
24
+ # Enforcing double quotes reduces the times where you need to change them
25
+ # when introducing an interpolation. Use single quotes only if their semantics
26
+ # are needed.
27
+ Style/StringLiterals:
28
+ EnforcedStyle: double_quotes
29
+
30
+ # We do not need to support Ruby 1.9, so this is good to use.
31
+ Style/SymbolArray:
32
+ Enabled: true
33
+
34
+ # Most readable form.
35
+ Style/OptionHash:
36
+ # A list of parameter names that will be flagged by this cop.
37
+ SuspiciousParamNames:
38
+ - options
39
+ - opts
40
+ - args
41
+ - paramsgit sttus
42
+ - parameters
43
+
44
+ # Mixing the styles looks just silly.
45
+ Style/HashSyntax:
46
+ EnforcedStyle: ruby19_no_mixed_keys
47
+
48
+ # has_key? and has_value? are far more readable than key? and value?
49
+ Style/PreferredHashMethods:
50
+ Enabled: false
51
+
52
+ # String#% is by far the least verbose and only object oriented variant.
53
+ Style/FormatString:
54
+ EnforcedStyle: percent
55
+
56
+ Style/CollectionMethods:
57
+ Enabled: true
58
+ PreferredMethods:
59
+ # inject seems more common in the community.
60
+ reduce: "inject"
61
+
62
+
63
+ # Either allow this style or don't. Marking it as safe with parenthesis
64
+ # is silly. Let's try to live without them for now.
65
+ Style/ParenthesesAroundCondition:
66
+ AllowSafeAssignment: false
67
+ Lint/AssignmentInCondition:
68
+ AllowSafeAssignment: false
69
+
70
+ # A specialized exception class will take one or more arguments and construct the message from it.
71
+ # So both variants make sense.
72
+ Style/RaiseArgs:
73
+ Enabled: false
74
+
75
+ # Indenting the chained dots beneath each other is not supported by this cop,
76
+ # see https://github.com/bbatsov/rubocop/issues/1633
77
+ Layout/MultilineOperationIndentation:
78
+ Enabled: false
79
+
80
+ # Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
81
+ # The argument that fail should be used to abort the program is wrong too,
82
+ # there's Kernel#abort for that.
83
+ Style/SignalException:
84
+ EnforcedStyle: only_raise
85
+
86
+ # Suppressing exceptions can be perfectly fine, and be it to avoid to
87
+ # explicitly type nil into the rescue since that's what you want to return,
88
+ # or suppressing LoadError for optional dependencies
89
+ Lint/SuppressedException:
90
+ Enabled: false
91
+
92
+ Layout/SpaceInsideBlockBraces:
93
+ # The space here provides no real gain in readability while consuming
94
+ # horizontal space that could be used for a better parameter name.
95
+ # Also {| differentiates better from a hash than { | does.
96
+ SpaceBeforeBlockParameters: false
97
+
98
+ # No trailing space differentiates better from the block:
99
+ # foo} means hash, foo } means block.
100
+ Layout/SpaceInsideHashLiteralBraces:
101
+ EnforcedStyle: no_space
102
+
103
+ # { ... } for multi-line blocks is okay, follow Weirichs rule instead:
104
+ # https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
105
+ Style/BlockDelimiters:
106
+ Enabled: false
107
+
108
+ # do / end blocks should be used for side effects,
109
+ # methods that run a block for side effects and have
110
+ # a useful return value are rare, assign the return
111
+ # value to a local variable for those cases.
112
+ Style/MethodCalledOnDoEndBlock:
113
+ Enabled: true
114
+
115
+ # Enforcing the names of variables? To single letter ones? Just no.
116
+ Style/SingleLineBlockParams:
117
+ Enabled: false
118
+
119
+ # Shadowing outer local variables with block parameters is often useful
120
+ # to not reinvent a new name for the same thing, it highlights the relation
121
+ # between the outer variable and the parameter. The cases where it's actually
122
+ # confusing are rare, and usually bad for other reasons already, for example
123
+ # because the method is too long.
124
+ Lint/ShadowingOuterLocalVariable:
125
+ Enabled: false
126
+
127
+ # Check with yard instead.
128
+ Style/Documentation:
129
+ Enabled: false
130
+
131
+ # This is just silly. Calling the argument `other` in all cases makes no sense.
132
+ Naming/BinaryOperatorParameterName:
133
+ Enabled: false
134
+
135
+ # There are valid cases, for example debugging Cucumber steps,
136
+ # also they'll fail CI anyway
137
+ Lint/Debugger:
138
+ Enabled: false
139
+
140
+ # Style preference
141
+ Style/MethodDefParentheses:
142
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ envato (1.0.0)
5
+ addressable (~> 2.3, >= 2.3.7)
6
+ faraday (~> 1.7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.1)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ crack (0.4.5)
14
+ rexml
15
+ diff-lcs (1.5.0)
16
+ docile (1.4.0)
17
+ faraday (1.10.2)
18
+ faraday-em_http (~> 1.0)
19
+ faraday-em_synchrony (~> 1.0)
20
+ faraday-excon (~> 1.1)
21
+ faraday-httpclient (~> 1.0)
22
+ faraday-multipart (~> 1.0)
23
+ faraday-net_http (~> 1.0)
24
+ faraday-net_http_persistent (~> 1.0)
25
+ faraday-patron (~> 1.0)
26
+ faraday-rack (~> 1.0)
27
+ faraday-retry (~> 1.0)
28
+ ruby2_keywords (>= 0.0.4)
29
+ faraday-em_http (1.0.0)
30
+ faraday-em_synchrony (1.0.0)
31
+ faraday-excon (1.1.0)
32
+ faraday-httpclient (1.0.1)
33
+ faraday-multipart (1.0.4)
34
+ multipart-post (~> 2)
35
+ faraday-net_http (1.0.1)
36
+ faraday-net_http_persistent (1.2.0)
37
+ faraday-patron (1.0.0)
38
+ faraday-rack (1.0.0)
39
+ faraday-retry (1.0.3)
40
+ hashdiff (1.0.1)
41
+ multipart-post (2.2.3)
42
+ public_suffix (5.0.0)
43
+ rake (13.0.6)
44
+ rexml (3.2.5)
45
+ rspec (3.11.0)
46
+ rspec-core (~> 3.11.0)
47
+ rspec-expectations (~> 3.11.0)
48
+ rspec-mocks (~> 3.11.0)
49
+ rspec-core (3.11.0)
50
+ rspec-support (~> 3.11.0)
51
+ rspec-expectations (3.11.1)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.11.0)
54
+ rspec-mocks (3.11.1)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.11.0)
57
+ rspec-support (3.11.1)
58
+ ruby2_keywords (0.0.5)
59
+ simplecov (0.21.2)
60
+ docile (~> 1.1)
61
+ simplecov-html (~> 0.11)
62
+ simplecov_json_formatter (~> 0.1)
63
+ simplecov-html (0.12.3)
64
+ simplecov_json_formatter (0.1.4)
65
+ vcr (6.1.0)
66
+ webmock (3.18.1)
67
+ addressable (>= 2.8.0)
68
+ crack (>= 0.3.2)
69
+ hashdiff (>= 0.4.0, < 2.0.0)
70
+
71
+ PLATFORMS
72
+ universal-darwin-21
73
+
74
+ DEPENDENCIES
75
+ bundler
76
+ envato!
77
+ rake (>= 10)
78
+ rspec (>= 3.0)
79
+ simplecov (>= 0.9)
80
+ vcr
81
+ webmock
82
+
83
+ BUNDLED WITH
84
+ 2.3.22
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2022 Ilya Brin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # Envato API - Ruby client ([gem](https://rubygems.org/gems/envato))
2
+
3
+ ## TODO
4
+
5
+ - examples
6
+ - documentation
7
+ - tests
8
+
9
+ # Available methods
10
+
11
+ ### V1 requests
12
+ ```ruby
13
+ # get /search/more_like_this
14
+ # GET https://api.envato.com/v1/discovery/search/search/more_like_this
15
+ client.search.more_like_this(item_id:, page: 1, page_size: 10)
16
+
17
+ # get /search/comment
18
+ # GET https://api.envato.com/v1/discovery/search/search/comment
19
+ client.search.comment(item_id:)
20
+
21
+ # get /search/item
22
+ # GET https://api.envato.com/v1/discovery/search/search/item
23
+ client.search.item
24
+
25
+ # get /number-of-files:{site}.json
26
+ # GET https://api.envato.com/v1/market/number-of-files:{site}.json
27
+ client.market.number_of_files(site:) # eg. "themeforest"
28
+
29
+ # get /total-users.json
30
+ # GET https://api.envato.com/v1/market/total-users.json
31
+ client.users.total
32
+
33
+ # get /total-items.json
34
+ # GET https://api.envato.com/v1/market/total-items.json
35
+ client.items.total
36
+
37
+ # get /item-prices:{item_id}.json
38
+ # GET https://api.envato.com/v1/market/item-prices:{item_id}.json
39
+ client.market.item_proces(item_id:)
40
+
41
+
42
+ # get /user:{username}.json
43
+ # GET https://api.envato.com/v1/market/user:{username}.json
44
+ client.users.info(username:)
45
+
46
+ # get /user-items-by-site:{username}.json
47
+ # GET https://api.envato.com/v1/market/user-items-by-site:{username}.json
48
+ client.users.items_by_site(username:)
49
+
50
+ # get /popular:{site}.json
51
+ # GET https://api.envato.com/v1/market/popular:{site}.json
52
+ client.market.popular(site:)
53
+
54
+ # get /categories:{site}.json
55
+ # GET https://api.envato.com/v1/market/categories:{site}.json
56
+ client.categories.list(site:)
57
+
58
+ # get /features:{site}.json
59
+ # GET https://api.envato.com/v1/market/features:{site}.json
60
+ client.features.list(site:)
61
+
62
+ # get /new-files:{site,category}.json
63
+ # GET https://api.envato.com/v1/market/new-files:{site,category}.json
64
+ client.new_files.list(site:)
65
+
66
+ # get /new-files-from-user:{username,site}.json
67
+ # GET https://api.envato.com/v1/market/new-files-from-user:{username,site}.json
68
+ client.users.new_fileslist(username:, site:)
69
+
70
+ # get /random-new-files:{site}.json
71
+ # GET https://api.envato.com/v1/market/random-new-files:{site}.json
72
+ client.market.random_new_files(site:)
73
+
74
+ # get /user-badges:{username}.json
75
+ # GET https://api.envato.com/v1/market/user-badges:{username}.json
76
+ client.users.badges(username:)
77
+
78
+ # get /private/user/earnings-and-sales-by-month.json
79
+ # GET https://api.envato.com/v1/market/private/user/earnings-and-sales-by-month.json
80
+ client.user.money_stats
81
+
82
+ get /private/user/account.json
83
+ GET https://api.envato.com/v1/market/private/user/account.json
84
+ client.user.account
85
+
86
+ get /private/user/username.json
87
+ GET https://api.envato.com/v1/market/private/user/username.json
88
+ client.user.name
89
+
90
+ get /private/user/email.json
91
+ GET https://api.envato.com/v1/market/private/user/email.json
92
+ client.user.email
93
+
94
+ ### V3 requests
95
+ get /author/sales
96
+ GET https://api.envato.com/v3/market/author/sales
97
+
98
+ get /author/sale?sale=
99
+ https://api.envato.com/v3/market/author/sale
100
+
101
+
102
+ get /buyer/download
103
+ GET https://api.envato.com/v3/market/buyer/download
104
+
105
+ get /buyer/list-purchases
106
+ GET https://api.envato.com/v3/market/buyer/list-purchases
107
+
108
+ get /buyer/purchase?code=
109
+ GET https://api.envato.com/v3/market/buyer/purchase
110
+
111
+ get /buyer/purchases
112
+ GET https://api.envato.com/v3/market/buyer/purchases
113
+
114
+ get /catalog/collection?id=
115
+ GET https://api.envato.com/v3/market/catalog/collection
116
+
117
+ get /catalog/item-version?id=
118
+ GET https://api.envato.com/v3/market/catalog/item-version
119
+
120
+ get /catalog/item?id=
121
+ GET https://api.envato.com/v3/market/catalog/item
122
+
123
+ put /user/bookmark_add?collectionid=&item_id=
124
+ PUT https://api.envato.com/v3/market/user/bookmark_add?collectionid=&item_id=
125
+
126
+ delete /user/bookmark_remove
127
+ DELETE https://api.envato.com/v3/market/user/bookmark_remove?id=
128
+
129
+ get /user/bookmarks_for_items?item_ids=123,1234,567
130
+ GET https://api.envato.com/v3/market/user/bookmarks_for_items
131
+
132
+ get /user/bookmarks - OK
133
+ GET https://api.envato.com/v3/market/user/bookmarks
134
+
135
+ post /user/collection_create?name=
136
+ POST https://api.envato.com/v3/market/user/collection_create
137
+
138
+ get /user/collection?id=
139
+ GET https://api.envato.com/v3/market/user/collection
140
+
141
+ get /user/collections - OK
142
+ GET https://api.envato.com/v3/market/user/collections
143
+ client.user.collections
144
+
145
+ put /user/favourite_collection_add?item_id=
146
+ PUT https://api.envato.com/v3/market/user/favourite_collection_add?item_id=
147
+ client.user.
148
+
149
+ get /user/statement - OK
150
+ GET https://api.envato.com/v3/market/user/statement
151
+ client.user.statement
152
+ ```
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
13
+
14
+ task :console do
15
+ exec "irb -I lib -r envato.rb"
16
+ end
data/envato.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "envato/version"
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "envato"
10
+ s.version = Envato::VERSION
11
+ s.summary = "WIP - Envato API client"
12
+ s.description = "WIP - Envato API wrapper written in Ruby"
13
+ s.authors = ["Ilya Brin"]
14
+ s.email = "ilya@codeplay.ru"
15
+ s.files = `git ls-files -z`.split("\x0")
16
+ s.executables = s.files.grep(%r{^bin/}) {|f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ s.homepage = "https://github.com/ruby-api-client/envato"
19
+ s.license = "MIT"
20
+
21
+ s.required_ruby_version = ">= 2.6"
22
+
23
+ s.metadata["rubygems_mfa_required"] = "true"
24
+
25
+ s.add_dependency "addressable", "~> 2.3", ">= 2.3.7"
26
+ s.add_dependency "faraday", "~> 1.7"
27
+
28
+ s.add_development_dependency "bundler"
29
+ s.add_development_dependency "rake", ">= 10"
30
+ s.add_development_dependency "rspec", ">= 3.0"
31
+ s.add_development_dependency "simplecov", ">= 0.9"
32
+ s.add_development_dependency "vcr"
33
+ s.add_development_dependency "webmock"
34
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Envato
4
+ class Client
5
+ BASE_URL = "https://api.envato.com"
6
+
7
+ attr_reader :token, :adapter
8
+
9
+ def initialize(token:, adapter: Faraday.default_adapter, stubs: nil)
10
+ @token = token
11
+ @adapter = adapter
12
+ @stubs = stubs # Test stubs for requests
13
+ end
14
+
15
+ def user
16
+ UserResource.new(self)
17
+ end
18
+
19
+ def users
20
+ UsersResource.new(self)
21
+ end
22
+
23
+ def search
24
+ SearchResource.new(self)
25
+ end
26
+
27
+ def market
28
+ MarketResource.new(self)
29
+ end
30
+
31
+ def markets
32
+ MarketsResource.new(self)
33
+ end
34
+
35
+ def bookmarks
36
+ BookmarksResource.new(self)
37
+ end
38
+
39
+ def item
40
+ ItemResource.new(self)
41
+ end
42
+
43
+ def connection
44
+ @connection ||= Faraday.new(BASE_URL) do |conn|
45
+ conn.request :authorization, :Bearer, token
46
+ conn.request :json
47
+ conn.request :url_encoded
48
+
49
+ conn.response :json, content_type: "application/json"
50
+
51
+ conn.adapter adapter, @stubs
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Envato
4
+ class Collection
5
+ # TODO: links: { next_page_url, prev_page_url, first_page_url, last_page_url }
6
+ # TODO: total_hits:
7
+ # TODO: took:
8
+ attr_reader :data, :items, :total
9
+
10
+ def self.from_response(response, key:, type:)
11
+ body = response.body
12
+ new(
13
+ data: body[key].map {|attrs| type.new(attrs) },
14
+ items: body["items"],
15
+ total: body["total"]
16
+ )
17
+ end
18
+
19
+ def initialize(data:, items:, total:)
20
+ @data = data
21
+ @items = items
22
+ @total = total
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Envato
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module Envato
6
+ class Object < OpenStruct
7
+ def initialize(attributes)
8
+ super to_ostruct(attributes)
9
+ end
10
+
11
+ # Convert Array or Hash to OpenStruct
12
+ def to_ostruct(obj)
13
+ case obj
14
+ when Hash
15
+ # rubocop:disable Style/HashTransformValues
16
+ OpenStruct.new(obj.map {|key, val| [key, to_ostruct(val)] }.to_h)
17
+ # rubocop:enable Style/HashTransformValues
18
+ when Array
19
+ obj.map {|o| to_ostruct(o) }
20
+ else
21
+ obj
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Envato
4
+ class User < Object; end
5
+ class Users < Object; end
6
+ class UsersTotal < Object; end
7
+ class UserSale < Object; end
8
+ class UserAccount < Object; end
9
+ class UserStatement < Object; end
10
+ class UserCollection < Object; end
11
+ class UserBookmark < Object; end
12
+ class UserBadge < Object; end
13
+ class Item < Object; end
14
+ class ItemPrice < Object; end
15
+ class ItemVersion < Object; end
16
+ class CollectionItem < Object; end
17
+ class Comment < Object; end
18
+ class Category < Object; end
19
+ end