Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. Added functionality to add filters to a resource for searches #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ Tmdb::Api.language("de")
The default language is english.
The API supports translations just be aware that it does not fall back to English in the event that a field hasn't been translated.


You can add miscellaneous query params filters with this:

```ruby
Tmdb::Person.search_filters(include_adult: true, page: 1, region: 'USA')
Tmdb::Movie.search_filters(include_adult: true, page: 1, region: 'USA', year: 1980, primary_release_year: 1980)
```

## Resources

Current available resources:
Expand Down
10 changes: 9 additions & 1 deletion lib/themoviedb/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def self.endpoint_id
@@endpoint_id[name.downcase]
end

def self.filters
@@filters ||= {}
end

def self.search_filters(options)
filters.merge! options
end

# Get the basic resource information for a specific id.
def self.detail(id, conditions = {})
search = Tmdb::Search.new("/#{endpoints[:singular]}/#{endpoint_id + id.to_s}")
Expand All @@ -37,7 +45,7 @@ def self.list(conditions = {})
def self.search(query)
search = Tmdb::Search.new
search.resource(endpoints[:singular].to_s)
search.query(query)
search.query(query).filter(filters)
search.fetch.collect do |result|
new(result)
end
Expand Down