marvel_crawler 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +141 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/marvel_crawler.rb +12 -0
- data/lib/marvel_crawler/api_client.rb +30 -0
- data/lib/marvel_crawler/api_request.rb +121 -0
- data/lib/marvel_crawler/api_response.rb +43 -0
- data/lib/marvel_crawler/connection.rb +39 -0
- data/lib/marvel_crawler/version.rb +3 -0
- data/marvel_crawler.gemspec +40 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b8b8fdf00abd2e2312960f06ff3e9daf0636871
|
4
|
+
data.tar.gz: ca0794883cb56d02dd60917d16648b396786f9fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40acee3ec029b762be7e19508192a3fea1a8cb67270b430a0e3c53e091e147062def83857990e59de2bba97f33060d6758157ad75a6c3e4e25f3efdf6cec1f13
|
7
|
+
data.tar.gz: d048bf4e9e0f6eb87234e181f9da1cee157d9e3f17a83ad84e53358f64ee773365cb1fcc451e0da38e6f9e115f7dc82fc366be2f22aa7fac4dffc51b027d9a27
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 ketan@fab.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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ketan Doshi
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# MarvelCrawler
|
2
|
+
|
3
|
+
Lightweight interface to communicate with the Marvel Comics API. It supports configurable pagination for all API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'marvel_crawler'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install marvel_crawler
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
You need to register on [Marvel Developer Portal](https://developer.marvel.com/) to get your public key and a private key. It requires to do the request on Marvel API.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
@crawler = MarvelCrawler.client
|
27
|
+
|
28
|
+
@crawler.configure do |config|
|
29
|
+
config.api_key = 'YOUR_API_KEY'
|
30
|
+
config.private_key = 'YOUR_PRIVATE_KEY'
|
31
|
+
config.record_per_page = 2 # Optional. By default its 5. You will get this much records per page.
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
OR
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
@crawler = MarvelCrawler.client
|
39
|
+
|
40
|
+
@crawler.api_key = 'YOUR_API_KEY'
|
41
|
+
@crawler.private_key = 'YOUR_PRIVATE_KEY'
|
42
|
+
@crawler.record_per_page = 2 # Optional. By default its 5. You will get this much records per page.
|
43
|
+
```
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
Below are the examples of supported resources.
|
48
|
+
All the methods returns an object of `MarvelCrawler::ApiResponse`
|
49
|
+
|
50
|
+
### Characters
|
51
|
+
|
52
|
+
- Gets lists of characters. [`GET /v1/public/characters`](http://developer.marvel.com/docs#!/public/getCreatorCollection_get_0)
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
@crawler.get_characters(page_num: 2) # Default page number is 1
|
56
|
+
@crawler.get_characters(name: 'A.I.M.', page_num: 2)
|
57
|
+
@crawler.get_characters(nameStartsWith: 'A', orderBy: 'modified')
|
58
|
+
```
|
59
|
+
|
60
|
+
- Fetches a single character by id. [`GET /v1/public/characters/{characterId}`](http://developer.marvel.com/docs#!/public/getCharacterIndividual_get_1)
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
@crawler.get_character(id: 1009144)
|
64
|
+
```
|
65
|
+
|
66
|
+
### Comics
|
67
|
+
|
68
|
+
- Gets lists of comics. [`GET /v1/public/comics`](https://developer.marvel.com/docs#!/public/getComicsCollection_get_6)
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
@crawler.get_comics(page_num: 2) # Default page number is 1
|
72
|
+
@crawler.get_comics(title: 'UNIVERSE X SPECIAL: CAP 1 (2001)')
|
73
|
+
@crawler.get_comics(format: 'magazine')
|
74
|
+
```
|
75
|
+
|
76
|
+
### Creators
|
77
|
+
|
78
|
+
- Gets lists of creators. [`GET /v1/public/creators`](https://developer.marvel.com/docs#!/public/getCreatorCollection_get_12)
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
@crawler.get_creators(page_num: 2) # Default page number is 1
|
82
|
+
```
|
83
|
+
|
84
|
+
### Events
|
85
|
+
|
86
|
+
- Gets lists of events. [`GET /v1/public/events`](https://developer.marvel.com/docs#!/public/getEventsCollection_get_18)
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
@crawler.get_events(page_num: 2) # Default page number is 1
|
90
|
+
```
|
91
|
+
|
92
|
+
### Series
|
93
|
+
|
94
|
+
- Gets lists of series. [`GET /v1/public/series`](https://developer.marvel.com/docs#!/public/getSeriesCollection_get_25)
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
@crawler.get_series(page_num: 2) # Default page number is 1
|
98
|
+
```
|
99
|
+
|
100
|
+
### Stories
|
101
|
+
|
102
|
+
- Gets lists of stories. [`GET /v1/public/stories`](https://developer.marvel.com/docs#!/public/getStoryCollection_get_32)
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
@crawler.get_stories(page_num: 2) # Default page number is 1
|
106
|
+
```
|
107
|
+
|
108
|
+
## Response
|
109
|
+
|
110
|
+
All the methods returns an object of `MarvelCrawler::ApiResponse`
|
111
|
+
The object contains following attributes:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
response.code => Http code returned from api
|
115
|
+
response.status => Status returned from api
|
116
|
+
response.results => Contains all the data for the resource
|
117
|
+
response.etag => etag returned from api
|
118
|
+
response.offset => offset returned from api
|
119
|
+
response.limit => limit returned from api which we have used
|
120
|
+
response.total => Total number of result available for this resource
|
121
|
+
response.count => Total number of result set returned by this call
|
122
|
+
response.message => Success OR Error message
|
123
|
+
```
|
124
|
+
|
125
|
+
## Development
|
126
|
+
|
127
|
+
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.
|
128
|
+
|
129
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
130
|
+
|
131
|
+
## Contributing
|
132
|
+
|
133
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ketandoshi/marvel_crawler. 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.
|
134
|
+
|
135
|
+
## License
|
136
|
+
|
137
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
138
|
+
|
139
|
+
## Code of Conduct
|
140
|
+
|
141
|
+
Everyone interacting in the MarvelCrawler project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ketandoshi/marvel_crawler/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "marvel_crawler"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'marvel_crawler/version'
|
2
|
+
require 'marvel_crawler/api_client'
|
3
|
+
|
4
|
+
module MarvelCrawler
|
5
|
+
class << self
|
6
|
+
# Alias for MarvelCrawler::ApiClient.new
|
7
|
+
# @return [MarvelCrawler::ApiClient]
|
8
|
+
def client
|
9
|
+
@api_client ||= MarvelCrawler::ApiClient.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'api_request'
|
2
|
+
|
3
|
+
module MarvelCrawler
|
4
|
+
class ApiClient
|
5
|
+
include MarvelCrawler::ApiRequest
|
6
|
+
|
7
|
+
attr_accessor :api_key, :private_key, :record_per_page
|
8
|
+
|
9
|
+
def initialize(api_key = nil, pri_key = nil, record_per_page = 5)
|
10
|
+
# All calls to the Marvel Comics API must pass your public key via an "apikey" parameter
|
11
|
+
@api_key = api_key
|
12
|
+
@private_key = pri_key
|
13
|
+
@record_per_page = record_per_page
|
14
|
+
end
|
15
|
+
|
16
|
+
# Customize default settings for the gem using block.
|
17
|
+
# MarvelCrawler::ApiClient.new.configure do |config|
|
18
|
+
# config.api_key = "xxx"
|
19
|
+
# config.private_key = "xxx"
|
20
|
+
# end
|
21
|
+
# If no block given, return the default Configuration object.
|
22
|
+
def configure
|
23
|
+
if block_given?
|
24
|
+
yield(self)
|
25
|
+
else
|
26
|
+
self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require_relative 'connection'
|
3
|
+
require_relative 'api_response'
|
4
|
+
|
5
|
+
module MarvelCrawler
|
6
|
+
module ApiRequest
|
7
|
+
|
8
|
+
class InvalidParameterError < StandardError; end
|
9
|
+
|
10
|
+
class InvalidClientError < StandardError; end
|
11
|
+
|
12
|
+
MARVEL_API_ROUTES = {
|
13
|
+
characters: %w(characters character character_comics character_events character_series character_stories),
|
14
|
+
comics: %w(comics comic comic_characters comic_creators comic_events comic_stories),
|
15
|
+
creators: %w(creators creator creator_comics creator_events creator_series creator_stories),
|
16
|
+
events: %w(events event event_characters event_creators event_comics event_stories event_series),
|
17
|
+
series: %w(series series series_characters series_comics series_creators series_events series_stories),
|
18
|
+
stories: %w(stories story story_characters story_comics story_creators story_events story_series)
|
19
|
+
}
|
20
|
+
|
21
|
+
MARVEL_API_ROUTES.each do |group_name, group_methods|
|
22
|
+
group_methods.each_with_index do |method_name, index|
|
23
|
+
entity = group_name.to_s
|
24
|
+
|
25
|
+
entity_id = entity_property = ''
|
26
|
+
entity_property = "/#{method_name.split('_').last}" if index > 1
|
27
|
+
|
28
|
+
define_method "get_#{method_name}" do |args = {}|
|
29
|
+
if index > 0
|
30
|
+
raise InvalidParameterError, 'You need to provide :id param.' if args[:id].nil?
|
31
|
+
entity_id = "/#{args[:id]}"
|
32
|
+
end
|
33
|
+
# Create the path url
|
34
|
+
path = entity + entity_id + entity_property
|
35
|
+
|
36
|
+
args[:page_num] ||= 1 if index != 1
|
37
|
+
|
38
|
+
make_request(
|
39
|
+
path,
|
40
|
+
sanitize_params(args, entity, entity_id, entity_property)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_request(path, options = {})
|
47
|
+
check_for_credentials
|
48
|
+
response = Connection.new.connect.get do |request|
|
49
|
+
request.url(path, options.merge(auth))
|
50
|
+
end
|
51
|
+
ApiResponse.new(response).format_response
|
52
|
+
end
|
53
|
+
|
54
|
+
def auth(ts_value = timestamp)
|
55
|
+
{
|
56
|
+
ts: ts_value,
|
57
|
+
apikey: api_key,
|
58
|
+
hash: generate_hash(ts_value)
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_hash(ts_value)
|
63
|
+
Digest::MD5.hexdigest(ts_value + private_key + api_key)
|
64
|
+
end
|
65
|
+
|
66
|
+
def timestamp
|
67
|
+
Time.now.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def sanitize_params(args, entity, entity_id, entity_property)
|
71
|
+
options = Hash.new.merge(pagination_params(args[:page_num]))
|
72
|
+
|
73
|
+
valid_params = get_entity_valid_params(entity, entity_id, entity_property)
|
74
|
+
|
75
|
+
options.merge(args.keep_if { |key, value| valid_params.include?(key) }) unless args.empty?
|
76
|
+
options
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_entity_valid_params(entity, entity_id, entity_property)
|
80
|
+
valid_params = Hash.new
|
81
|
+
|
82
|
+
case entity
|
83
|
+
when 'characters'
|
84
|
+
if entity_id.nil?
|
85
|
+
valid_params = %w(name nameStartsWith modifiedSince comics series events stories orderBy limit offset).map { |e| e.to_sym}
|
86
|
+
elsif !entity_id.nil? && entity_property.nil?
|
87
|
+
valid_params = %w(characterId).map { |e| e.to_sym}
|
88
|
+
else
|
89
|
+
# valid_params for other methods
|
90
|
+
end
|
91
|
+
when 'comics'
|
92
|
+
# comics params
|
93
|
+
when 'creators'
|
94
|
+
# creators params
|
95
|
+
when 'events'
|
96
|
+
# events params
|
97
|
+
when 'series'
|
98
|
+
# series params
|
99
|
+
when 'stories'
|
100
|
+
# stories params
|
101
|
+
end
|
102
|
+
|
103
|
+
valid_params
|
104
|
+
end
|
105
|
+
|
106
|
+
def pagination_params(page_num)
|
107
|
+
return {} if page_num.nil?
|
108
|
+
{
|
109
|
+
limit: record_per_page,
|
110
|
+
offset: ((page_num - 1) * record_per_page)
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
def check_for_credentials
|
115
|
+
[:api_key, :private_key].each do |key|
|
116
|
+
raise InvalidClientError, "You need to provide :#{key} param." if self.send(key).nil?
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module MarvelCrawler
|
2
|
+
class ApiResponse
|
3
|
+
|
4
|
+
attr_accessor :response, :code, :status, :results, :etag, :offset, :limit, :total, :count, :message
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@response = response.body
|
8
|
+
@code = @response['code']
|
9
|
+
@status = @response['status']
|
10
|
+
@results = nil
|
11
|
+
@etag = nil
|
12
|
+
@offset = nil
|
13
|
+
@limit = nil
|
14
|
+
@total = nil
|
15
|
+
@count = nil
|
16
|
+
@message = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def format_response
|
20
|
+
case @code
|
21
|
+
when 200
|
22
|
+
@results = @response['data']['results'].dup
|
23
|
+
@etag = @response['etag']
|
24
|
+
@offset = @response['data']['offset']
|
25
|
+
@limit = @response['data']['limit']
|
26
|
+
@total = @response['data']['total']
|
27
|
+
@count = @response['data']['count']
|
28
|
+
@message = 'Success'
|
29
|
+
else
|
30
|
+
@message = "Error: #{@response['status']}"
|
31
|
+
end
|
32
|
+
@response = nil
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
# Class for testing purpose
|
40
|
+
class Klass
|
41
|
+
attr_accessor :body
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module MarvelCrawler
|
5
|
+
class Connection
|
6
|
+
|
7
|
+
@@active_connection = nil
|
8
|
+
|
9
|
+
attr_accessor :base_url, :headers
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@base_url = 'https://gateway.marvel.com/v1/public/'
|
13
|
+
@headers = {
|
14
|
+
content_type: 'application/json',
|
15
|
+
user_agent: "marvel_crawler v#{MarvelCrawler::VERSION}"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def connect
|
20
|
+
return @@active_connection unless @@active_connection.nil?
|
21
|
+
|
22
|
+
options = {
|
23
|
+
url: @base_url,
|
24
|
+
headers: @headers
|
25
|
+
}
|
26
|
+
|
27
|
+
@@active_connection = Faraday.new(options) do |conn|
|
28
|
+
# Request encodes as "application/x-www-form-urlencoded" if not already encoded or of another type
|
29
|
+
conn.use Faraday::Request::UrlEncoded
|
30
|
+
# Converts parsed response bodies to a Hashie::Mash if they were of Hash or Array type
|
31
|
+
# conn.use Faraday::Response::Mashify
|
32
|
+
# Parse the json response
|
33
|
+
conn.use Faraday::Response::ParseJson
|
34
|
+
# Make requests with Net::HTTP
|
35
|
+
conn.adapter(Faraday.default_adapter)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "marvel_crawler/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "marvel_crawler"
|
8
|
+
spec.version = MarvelCrawler::VERSION
|
9
|
+
spec.authors = ["Ketan Doshi"]
|
10
|
+
spec.email = ["ketandoshi81@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Lightweight Marvel Comics API Interface}
|
13
|
+
spec.description = %q{Lightweight interface to communicate with the Marvel Comics API}
|
14
|
+
spec.homepage = "https://github.com/ketandoshi/marvel-crawler"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# # to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
|
37
|
+
spec.add_runtime_dependency 'faraday', '~> 0.14.0'
|
38
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 0.12.2'
|
39
|
+
spec.add_runtime_dependency 'hashie', '~> 3.5', '>= 3.5.7'
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marvel_crawler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ketan Doshi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.14.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.14.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday_middleware
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.12.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.12.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: hashie
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.5'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 3.5.7
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '3.5'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 3.5.7
|
103
|
+
description: Lightweight interface to communicate with the Marvel Comics API
|
104
|
+
email:
|
105
|
+
- ketandoshi81@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".travis.yml"
|
113
|
+
- CODE_OF_CONDUCT.md
|
114
|
+
- Gemfile
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- bin/console
|
119
|
+
- bin/setup
|
120
|
+
- lib/marvel_crawler.rb
|
121
|
+
- lib/marvel_crawler/api_client.rb
|
122
|
+
- lib/marvel_crawler/api_request.rb
|
123
|
+
- lib/marvel_crawler/api_response.rb
|
124
|
+
- lib/marvel_crawler/connection.rb
|
125
|
+
- lib/marvel_crawler/version.rb
|
126
|
+
- marvel_crawler.gemspec
|
127
|
+
homepage: https://github.com/ketandoshi/marvel-crawler
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.4.6
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Lightweight Marvel Comics API Interface
|
151
|
+
test_files: []
|