GithubHelp home page GithubHelp logo

gkye / themoviedatabaseswiftwrapper Goto Github PK

View Code? Open in Web Editor NEW
148.0 8.0 37.0 7.91 MB

Swift wrapper for themoviedb.org api v3

License: MIT License

Swift 99.61% Ruby 0.39%
swift json tmdb tmdb-api movies-api

themoviedatabaseswiftwrapper's Introduction

Platforms Swift Package Manager CocoaPods Compatible codebeat badge GitHub issues GitHub license

Usage

  1. Get an API key-> themoviedb.org

"A TMDb user account is required to request an API key."*

2. View Wikis for examples

Installation

TMDBSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "TMDBSwift"

TMDBSwift is available through Swift Package Manager. To install it to your project, simply add the following to your Package.swift file:

.package(url: "https://github.com/gkye/TheMovieDatabaseSwiftWrapper", from: "0.7.0"),

ENDPOINTS

Author

George Kye

themoviedatabaseswiftwrapper's People

Contributors

djpearce avatar gonzo-oin avatar hegedus90 avatar martinp7r avatar michelasso avatar paxos avatar piars777 avatar samuelreganpaul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

themoviedatabaseswiftwrapper's Issues

`MoveDetailedMDB.movie(...)` (and MovieMDB.movie(...) ?) not working as expected

@gkye @djpearce
Sorry to bother you.
I'm not sure I understand the data structure for these nested types correctly, but imdb_id (and others) seem to not be decoding correctly.

First of all, it's a string in json and the prop is Int!

I augmented tests below to confirm. Let me open a PR soon.

func testMovieById() {
var data: MovieDetailedMDB?
let expectation = self.expectation(description: "Wait for data to load.")
MovieMDB.movie(movieID: 7984) { _, movie in
data = movie
expectation.fulfill()
}
waitForExpectations(timeout: expecationTimeout, handler: nil)
XCTAssertNotNil(data)
XCTAssertEqual(data?.title, "In the Name of the Father")
}

    func testMovieById() {
        var data: MovieDetailedMDB?
        let expectation = self.expectation(description: "Wait for data to load.")

        MovieMDB.movie(movieID: 7984) { ddd, movie in
            debugPrint(String(data: ddd.data!, encoding: .utf8))
            data = movie
            expectation.fulfill()
        }
        waitForExpectations(timeout: expectationTimeout, handler: nil)
        XCTAssertNotNil(data)
        XCTAssertEqual(data?.title, "In the Name of the Father")
        XCTAssertEqual(data?.imdb_id, "tt0107207") // fails `nil`
        XCTAssertEqual(data?.homepage, "") // fails `nil`
        XCTAssertEqual(data?.runtime, 133) // fails `nil`
    }

    func testMovieDetailById() {
        var data: MovieDetailedMDB?
        let expectation = self.expectation(description: "Wait for data to load.")

        MovieDetailedMDB.movie(movieID: 7984) { ddd, movie in
            debugPrint(String(data: ddd.data!, encoding: .utf8))
            data = movie
            expectation.fulfill()
        }
        waitForExpectations(timeout: expectationTimeout, handler: nil)
        XCTAssertNotNil(data)
        XCTAssertEqual(data?.title, "In the Name of the Father")
        XCTAssertEqual(data?.imdb_id, "tt0107207") // fails `nil`
        XCTAssertEqual(data?.homepage, "") // fails `nil`
        XCTAssertEqual(data?.runtime, 133) // fails `nil`
    }

Importing into existing Xcode project

Hi. I know this isn't a technical issue with TMDBSwift, but I just discovered it, and I'm a new developer. Very new. So here's my stupid "issue": I don't even know how to import it into my Xcode project to start using it!

I have searched the web, stack overflow, and just can't see an answer. I feel so stupid, but wanted to reach out to you directly to see if you could give me the probably-super-simple step-by-step instructions. Closest I found is this: http://stackoverflow.com/questions/34099841/import-my-custom-module-framework-xcode-swift - but I have tried adding the .h file via 'settings > embedded binaries' and 'settings > linked frameworks and libraries'... when I try the latter, the TMDBswift.h file appears under 'linked frameworks and libraries' yet every time I try to import TMDBSwift at the top of my ViewController.swift file, xcode complains 'no such module'.

Again, I'm sorry. I'm sure it's simple (when you know) but this is my first time trying to add an external framework to a project. Thanks for any help (and you can delete this 'issue' afterwards)!

Crash with an empty result

The application crashes when an empty list is returned. I attach screenshots from Crashlytics.

  1. In the FindMDB.swift file on line 123:
    data = FindMDB.init(json: apiReturn.json!) <- force unwrapping
    Screen: kp crashlytics firebase console 2018-06-24 15-43-41

  2. In the MovieMDB.swift file on line 27:
    detailed = MovieDetailedMDB.init(results: apiReturn.json!) <- force unwrapping
    Screen: kp crashlytics firebase console 2018-06-24 15-54-23

Also in this file all methods have force unwrapping.
Thank you for your work.

demo doesn't run

"To run the example project, clone the repo, and run pod install from the Demo directory first."

[!] No 'Podfile' found in the project directory.

Extra argument in call (API key)

Hi!

First of all, thank you for the library!

(Actually this is not an issue, it's a question or even a help request.)

Recently I updated my pods and I saw that you released a new version (congratulations!). I noticed in your commits that you removed api key parameters, but there's a great lack of documentation. How can we use it now?
I guess there's some kind of preparatory function but how can I find it?

I used to just call ConfigurationMDB.configuration, TVMDB.popular and SearchMDB.tv. That's it. And all this worked for me.

Thanks in advance for your reply!

Fix ArrayObject protocol for swift3

The function below worked perfectly fine in swift2 but since updating to swift3 initializing no longer takes place and the for-loop is skipped after the first attempt. I've set multitudes of break points but still can't understand why this happens

//MARK: Array protocol returns an array of types by initlizaing using the json passed
public protocol ArrayObject {
  init(results: JSON)
}

extension ArrayObject {
  public static func initialize<T:ArrayObject>(json: JSON) -> [T] {
    var array = [T]()
    //For loop bails after the first attempt **
    for i in 0..<json.count{
      array.append(T.init(results: json[i]))
    }
    return array
  }
}

Wrong parse image data

Request:

MovieMDB.movie(movieID: tmdbID) { (value, find) in
                print(find?.belongs_to_collection?.backdrop_path as Any)
                print(find?.belongs_to_collection?.poster_path as Any)
                print(value.json?["poster_path"] as Any)
                print(value.json?["backdrop_path"] as Any)
                print("https://image.tmdb.org/t/p/w500/\(value.json?["poster_path"])")
                print("https://image.tmdb.org/t/p/w500/\(value.json?["backdrop_path"])")
}

ConsoleOutput:

nil
nil
Optional(/j4CBsXaGcltcHGbcxsWD5VfEaiU.jpg)
Optional(/i26FIo5vJrR4u8ZZBm8o5Q4T9di.jpg)
https://image.tmdb.org/t/p/w500/Optional(/j4CBsXaGcltcHGbcxsWD5VfEaiU.jpg)
https://image.tmdb.org/t/p/w500/Optional(/i26FIo5vJrR4u8ZZBm8o5Q4T9di.jpg)

Contextual closure type '(Data?, URLResponse?, Error?)

Hi,

first of all: thanks for this all!

As a total beginner in both swift and ... eh... this here (;-)) I managed to add everything to an existing project but there were two sections leaving me with error messages from Xcode. One of them was just a usage of outdated code. The warning said:
"characters is deprecated". So I changed it:

old:
text.characters.count
new:
text.count

I'm having a real pain with the other issue. It's in the file Client.swift

There's the following block:

struct Client{
  static func networkRequest(url: String, parameters: [String : AnyObject], completion: @escaping (ClientReturn) -> ()) -> (){
    var cReturn = ClientReturn()
    HTTPRequest.request(url, parameters: parameters){
      rtn in                                       // <- here's the error!
      if rtn.2 == nil{
        let json = try! JSON(data: rtn.0!)
        cReturn.error = nil
        cReturn.json = json
        if(json["page"].exists()){
          cReturn.pageResults = PageResultsMDB.init(results: json)
        }else{
          cReturn.pageResults = nil
        }
      }else{
        cReturn.error = rtn.2 as NSError?
        cReturn.json = nil
        cReturn.pageResults = nil
      }
      completion(cReturn)

    }

where it says "rtn in" there's an error message saying:
"Contextual closure type '(Data?, URLResponse?, Error?) -> ()' expects 3 arguments, but 1 was used in closure body".

It advises:
"Insert ',<#arg#>,<#arg#> '"

Can anyone tell me what to do here? I've never heard of that. I searched the web for this but I just don't get the cases described there.

Thanks in advance and have a great week

Patrick

P.S.: I'm totally new to GitHub but I thought this might be the right place to ask this. If not, please don't be angry :-/

Swift error on simple query

screenshot 2019-02-13 at 22 53 01

For some reason I get this error on a simple Discover query. I declared the API_KEY as being a String.

Any ideas how to fix it?

Thanks!

Ambiguous reference to member 'discoverMovies(_:language:page:sort_by:completion:)'

Whenever I am trying to use the discover function:

DiscoverMovieMDB.discoverMovies(apiKey, language: "EN", page: nil, sort_by: DiscoverSortByMovie.primary_release_date_desc) { (returnData, movies) in

        }

It tells me that there is an Ambiguous reference to member 'discoverMovies(_:language:page:sort_by:completion:)' I am using the Swift 3 branch.

Am I doing something wrong?

images and video entry point

Hi,
Entrypoint for image and video's movie are not yet implemented. Can you make public the method final func networkRequest(url url: String, parameters: [String : AnyObject], completion: (ClientReturn) -> ()) -> ()

api don't return movie genre

hi,
first thank you for your job and i have a request about the api.
api don't return movie genre. can you fix this please?
thank you

Using Mock data for unit tests

v3 of the API seems mostly stable at this time and v4 has been started in some capacity. Our unit tests currently are really integration tests that run directly off the API. While this type of testing is good to have it shouldn't be our main source for unit tests. I think we should look to enhance our unit test suite with mock data and focus more on testing the parameters, the creation of the network request, and the decode-ability of individual models.

We can then look to have suites of tests run specifically on pull requests and pushes to master or on a cron job to continue to test the validity of the APIs contracts less frequently and away from PRs.

While it may not matter for the frequency of contribution to this repo, I think it's good to stay towards leading standards either way.

Api get Movie detail return nil for production_companies and production_countries

The code I tried is taken from the wiki:

MovieMDB.movie(apikey, movieID: 7984, language: "en"){
      apiReturn, movie in
      if let movie = movie{
        print(movie.title)
        print(movie.revenue)
        print(movie.genres[0].name)
        print(movie.production_companies?[0].name)
      }
    }

production_companies, production_countries appear in apiReturn, but

print(movie.production_companies?[0].name)

return nil

New podspec needs updated to trunk

I can't run pod trunk push TMDBSwift.podspec myself because my email isn't added as an owner of the repo. @gkye Could you help me get added to the owners group of the podspec, or push the update yourself.

Adding other people as contributors

The first person to push a Podspec version to Trunk can add other maintainers. For example, to add [email protected] to the library ARAnalytics:

$ pod trunk add-owner ARAnalytics [email protected]
This will then list all the known library owners. Note: they need to already have registered an account set up on trunk in order for you to add them to a library.

Swift Package Manager Support

Since Xcode can now (as of Xcode 11 beta) handle Swift Package Manager dependencies, could you please add support, so that your library can be fetched by the Swift PM insted of using CocoaPods?

Minimum supported target iOS 14

With the migration to codable mostly done, I think it's worth asking if we could talk about bumping the minimum targets to the iOS 14 era of versions. This opens up the door for maybe using Async/Await and reintroducing a demo project in SwiftUI amongst other changes.

Curious on others thoughts on the matter!

Remove erroneous 5.0.1 tag

It looks like there was a typo when adding the 5.0.1 tag since it goes so far out of the semantic versioning iteration. Could this be deleted for consistency?

API to retrieve the image data?

Hello,

Is there a way to retrieve the image dat? I now I can retrieve the filename (e.g. /rRgkZUNgD68DD7xDsv1XMmQBjld.jpg), but there is no clear way to retrieve the actual image. If it's up to client to retrieve it, how is the URL constructed? Let's assume https://api.themoviedb.org/3/person/1042728:

  {
    "aspect_ratio": 0.66666666666667,
    "file_path": "/uSSUrSdzH73bcy5hWIB5SZFzuFm.jpg",
    "height": 705,
    "iso_639_1": null,
    "vote_average": 5.312,
    "vote_count": 1,
    "width": 470
  }

These URLs return an error: ๐Ÿค”

https://api.themoviedb.org/3/person/1042728/uSSUrSdzH73bcy5hWIB5SZFzuFm.jpg https://api.themoviedb.org/3/person/1042728/images/uSSUrSdzH73bcy5hWIB5SZFzuFm.jpg

Wiki Documention Not Updated

Hello,

It looks like there is an issue with the Wiki Documentation, when I updated to the newest version I am getting errors with discoverMovies function, looks like things may have moved to a params argument rather than spelled out like they were. Not sure what the params are supposed to look like for your functions.

Crash if tmdb is unavailable

If TMDB returns a page with error 502, the application crashes, so it tries to parse the answer.
The crash occurs in the Client.swift in line 42

let json = try! JSON(data: data!)

Error:
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

po response.debugDescription:
"Optional(<NSHTTPURLResponse: 0x1c483e8a0> { URL: https://api.themoviedb.org/3/find/tt0258000?api_key=mykey&external_source=imdb_id } { Status Code: 502, Headers {\n Connection = (\n \"keep-alive\"\n );\n \"Content-Length\" = (\n 166\n );\n \"Content-Type\" = (\n \"text/html\"\n );\n Date = (\n \"Sat, 17 Feb 2018 23:00:13 GMT\"\n );\n Server = (\n openresty\n );\n \"X-RateLimit-Limit\" = (\n 40\n );\n \"X-RateLimit-Remaining\" = (\n 39\n );\n \"X-RateLimit-Reset\" = (\n 1518908423\n );\n} })"

ClientReturn has no member MBDBReturn

When using your Wiki code

        DiscoverMDB.discover(apiKey, discoverType: "tv", language: nil){
            apiReturn in
            let tvshows = apiReturn.MBDBReturn as! [TVMDB]
            print(tvshows[0].name)
            print(tvshows[0].overview)
            print(tvshows[0].popularity)
        }

I get that ClientReturn has no member MBDBReturn?

tvos TMDBSwift

HI
I try to add pod 'TMDBSwift' for tv os build on cocoad pod, but iit's not running.

[!] The platform of the target TiburonVideo_tvOS(tvOS 13.0) is not compatible withTMDBSwift (0.5.1), which does not support tvOS.

How can it be solved?

Bests

Alex

Application is not building

HI,

I cloned the Repo using the Github desktop client. Am trying to run/build the project. Every time i do this am getting the success message, but the application is not running on any devices. Its displaying "Build Succeeded"
Am using Xcode 9.4.1

Demo App Submodule Missing

From what I can tell the demo app submodule was removed or at least the path was broken in some way.

Are we safe to remove reference to it for the time being until a potentially new demo app is constructed?

error with swift 3

Hi,
I update my project to swift 3 but i encounter some compilation problem with the pod tmdbswift.
Did you update the pod to support swift 3?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.