# Movie search API
url1 <- "http://api.nytimes.com/svc/movies/v2/reviews/search.json?"
key1 <- "api-key=109ff0ae5d9345fd93c50a873e45225c"
kurl1 <- paste0(url1, key1)
r <- GET(kurl1)
r
## Response [http://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=109ff0ae5d9345fd93c50a873e45225c]
##   Date: 2017-04-01 12:33
##   Status: 200
##   Content-Type: application/json; charset=UTF-8
##   Size: 16.2 kB
#response from API
status_code(r)
## [1] 200
#check if the status is 200 which means success
#JSON to data frame.

if (status_code(r) == 200)
 {movie_review <- fromJSON(kurl1)
 }

json_raw <- httr::content(r, type = "text", encoding = "UTF-8")

## get the number of results
results <- 
    json_raw %>% 
    enter_object("num_results") %>%
    append_values_string("num_results") %>% 
    select(num_results)

results
##   num_results
## 1          20
movie_review_df <- data.frame(movie_review$results)
movie_review_df <-  data.frame(movie_review_df$display_title ,movie_review_df$mpaa_rating,movie_review_df$summary_short)
colnames(movie_review_df) = c("Title","Rating","Summary")
kable(movie_review_df)
Title Rating Summary
Five Came Back A screen adaptation of Mark Harris’s 2014 book adds visuals to the story of five Hollywood directors who served in World War II with cameras in tow.
The Blackcoat’s Daughter R Three narratives converge in a gorgeously filmed, deeply unsettling horror film about girls stranded at their boarding school during midterm break.
The Death of Louis XIV Albert Serra’s new film is a showcase for a beloved star of French cinema, Jean-Pierre Léaud.
God Knows Where I Am A documentary recalls the life of Linda Bishop, who had a psychotic disorder and fell through the cracks of New Hampshire’s medical establishment.
Ghost in the Shell PG-13 Scarlett Johansson, playing a cyborg called Major, rises above it all in the thrill-free science fiction thriller.
All This Panic This limber, light-footed documentary becomes a sort of dreamy film diary for the girls it profiles.
The Boss Baby PG An animated feature starring a newborn with an oh-so-familiar voice may confuse the kiddies, but grown-ups should get a kick out of it.
Carrie Pilby A 19-year-old British prodigy fresh out of Harvard pursues some semblance of a normal life in New York.
David Lynch - The Art Life A documentary profile of this filmmaker focuses not on his big-screen features, but on his early development as a painter.
Here Alone A woman struggles to survive the aftermath of a deadly virus in a movie that is more psychodrama than postapocalyptic adventure.
Tony Conrad: Completely in the Present This documentary captures the antic personality of Mr. Conrad, an avant-garde musician and experimental filmmaker who died last year.
Live Cargo This first feature by the director Logan Sandler has great acting, stunning imagery and a vivid Caribbean setting. But its words prove elusive.
Cezanne and I R A new film offers an intimate, searching portrait of the turbulent friendship between the writer and the painter.
The Discovery A science-fiction romance starring Robert Redford begins with the premise that proof of what’s next has been found. After that, things turn ugly.
The Zookeeper’s Wife PG-13 This true story of a couple who sheltered Jews beneath the Warsaw Zoo has tender moments but its portrayal of the Nazi invasion is too timid and sanitized.
Karl Marx City In this documentary, a filmmaker returns to her hometown in the former East Germany seeking personal and political insight.
Phillauri Anshai Lal’s Bollywood movie uses a friendly ghost to turn a contemporary comedy into a historical drama that includes a massacre under British rule.
Life R This movie offers proof of life on another planet, sure, but it is also the occasion for another “Alien”-type deadly game of hide-and-seek.
I Called Him Morgan The director Kasper Collin has created a suave and sensitive documentary about the life and death of the great trumpeter Lee Morgan.
American Anarchist A dialogue between the director and the author of “The Anarchist Cookbook” is at the heart of this documentary.
#Add conditions to the movie reviews API

url2 <-  "https://api.nytimes.com/svc/movies/v2/reviews/picks.json?"
key2 <-  "api-key=109ff0ae5d9345fd93c50a873e45225c"
query <- "&query=Black"
pd <-    "&publication-date=2017-03-30"
cp <-    "&critics-pick=Y"
kurl2 <- paste0(url2, key2,query, pd,cp)
kurl2
## [1] "https://api.nytimes.com/svc/movies/v2/reviews/picks.json?api-key=109ff0ae5d9345fd93c50a873e45225c&query=Black&publication-date=2017-03-30&critics-pick=Y"
r2 <- GET(kurl2)
status_code(r2)
## [1] 200
if (status_code(r2) == 200)
 {movie_review2 <- fromJSON(kurl2)
 }

movie_review_df2 <- data.frame(movie_review2)
movie_review_df3 <-  data.frame(movie_review_df2$results.display_title,
                                movie_review_df2$results.mpaa_rating,
                                movie_review_df2$results.critics_pick,
                                movie_review_df2$results.summary_short,
                                movie_review_df2$results.publication_date
                                )

colnames(movie_review_df3) = c("Title","Rating","Pick","Summary","Date of Publication")

movie_review_df4 <- data.frame(movie_review_df2$results.link)
colnames(movie_review_df4) = c("Type","URL","Link_Text")

movie <- cbind.data.frame(movie_review_df3,movie_review_df4)
kable(movie)
Title Rating Pick Summary Date of Publication Type URL Link_Text
The Blackcoat’s Daughter R 1 Three narratives converge in a gorgeously filmed, deeply unsettling horror film about girls stranded at their boarding school during midterm break. 2017-03-30 article http://www.nytimes.com/2017/03/30/movies/the-blackcoats-daughter-review.html Read the New York Times Review of The Blackcoat’s Daughter
Amanda Knox 1 This documentary about the case of an exchange student killed in Italy focuses less on an accused killer and more on unprincipled journalism and unapologetic sexism. 2016-09-29 article http://www.nytimes.com/2016/09/30/movies/review-amanda-knox-documentary.html Read the New York Times Review of Amanda Knox
A Hologram for the King R 1 Set in Saudi Arabia, this subdued absurdist farce reflects on American decline and runaway technology. 2016-04-21 article http://www.nytimes.com/2016/04/22/movies/review-a-hologram-for-the-king-is-elevated-by-tom-hankss-portrayal-of-an-american-everyman.html Read the New York Times Review of A Hologram for the King
White Lies 1 A quiet tale of cultural oppression, in Maori and English, set in the New Zealand of more than 100 years ago. 2016-03-03 article http://www.nytimes.com/2016/03/04/movies/white-lies-review.html Read the New York Times Review of White Lies
The Black Panthers: Vanguard of the Revolution 1 Stanley Nelson’s new documentary chronicles the organization’s rise and turbulent times. 2015-09-01 article http://www.nytimes.com/2015/09/02/movies/review-the-black-panthers-captures-a-militant-movements-soul-and-swagger.html Read the New York Times Review of The Black Panthers: Vanguard of the Revolution
Blackhat R 1 In Michael Mann’s “Blackhat,” a hacker is provisionally released from prison to combat a cybercriminal who has sabotaged a nuclear plant and manipulated a financial market. 2015-01-15 article http://www.nytimes.com/2015/01/16/movies/blackhat-a-cyberthriller-starring-chris-hemsworth.html Read the New York Times Review of Blackhat
Beyond the Lights PG-13 1 In Gina Prince-Bythewood’s “Beyond the Lights,” a pop star lives a lonely life before meeting a police officer with ambitions of his own. 2014-11-13 article http://www.nytimes.com/2014/11/14/movies/beyond-the-lights-a-divas-romance.html Read the New York Times Review of Beyond the Lights
21 Years: Richard Linklater 1 “21 Years: Richard Linklater,” by Michael Dunaway and Tara Wood, offers a star-studded tribute to the director of “Boyhood,” “School of Rock” and “Slacker.” 2014-11-06 article http://www.nytimes.com/2014/11/07/movies/21-years-richard-linklater-a-documentary.html Read the New York Times Review of 21 Years: Richard Linklater
Through a Lens Darkly: Black Photographers and the Emergence of a People 1 “Through a Lens Darkly,” a film on the history of African-American photography, is also a family memoir and a tribute to unsung artists. 2014-08-26 article http://www.nytimes.com/2014/08/27/movies/through-a-lens-darkly-on-african-american-photography.html Read the New York Times Review of Through a Lens Darkly: Black Photographers and the Emergence of a People
Code Black 1 The documentary “Code Black” takes place in the emergency room of Los Angeles County General Hospital. 2014-06-19 article http://www.nytimes.com/2014/06/20/movies/code-black-a-heath-care-documentary-by-ryan-mcgarry.html Read the New York Times Review of Code Black
Blackfish PG-13 1 The documentary “Blackfish” considers the story of Tilikum, a bull orca, in a scathing look at SeaWorld. 2013-07-18 article http://www.nytimes.com/2013/07/19/movies/blackfish-a-documentary-looks-critically-at-seaworld.html Read the New York Times Review of Blackfish
Bernie PG-13 1 Shirley MacLaine and Jack Black form an unlikely bond in “Bernie,” Richard Linklater’s dark comedy. 2012-04-26 article http://www.nytimes.com/2012/04/27/movies/bernie-with-jack-black-and-shirley-maclaine.html Read the New York Times Review of Bernie
Black Butterflies Not Rated 1 Paula Van der Oest’s film “Black Butterflies” is a biopic about the poet Ingrid Jonker, who has been called the Sylvia Plath of South Africa. 2012-03-01 article http://www.nytimes.com/2012/03/02/movies/black-butterflies-a-biopic-about-the-poet-ingrid-jonker.html Read the New York Times Review of Black Butterflies
Black Death R 1 As it turns out, no one is without sin in “Black Death,” a grungy, cynical little number from the British director Christopher Smith. 2011-03-10 article http://www.nytimes.com/2011/03/11/movies/black-death-and-dark-ages-drama.html Read the New York Times Review of Black Death
Black Swan R 1 In “Black Swan” Natalie Portman plays an ambitious ballerina straining to handle stardom. 2010-12-02 article http://www.nytimes.com/2010/12/03/movies/03black.html Read the New York Times Review of Black Swan
Kuroneko Not Rated 1 “Kuroneko,” a Japanese movie from 1968, seen in a new print, includes two avenging female spirits and brutal samurai. 2010-10-21 article http://www.nytimes.com/2010/10/22/movies/22kuro.html Read the New York Times Review of Kuroneko
Stark Raving Black Not Rated 1 in “Stark Raving Black,” Lewis Black’s concert movie, the comedian is at his most eloquently splenetic. 2009-10-07 article http://www.nytimes.com/2009/10/08/movies/08stark.html Read the New York Times Review of Stark Raving Black
Year One PG-13 1 Harold Ramis’s “Year One” is a thoroughly, sometimes gaggingly broad and sly conceptual laugh-in. 2009-06-18 article http://www.nytimes.com/2009/06/19/movies/19year.html Read the New York Times Review of Year One
Kung Fu Panda PG 1 At once fuzzy-wuzzy and industrial strength, the tacky-sounding “Kung Fu Panda” is high concept with a heart. 2008-06-06 article http://www.nytimes.com/2008/06/06/movies/06pand.html Read the New York Times Review of Kung Fu Panda
DarkBlueAlmostBlack 1 If peace lies in acceptance, then no one told the filmmaker Daniel Sánchez Arévalo, whose first feature portrays repressed longing with been-there, done-that assurance. 2007-10-19 article http://www.nytimes.com/2007/10/19/movies/19roun-003.html Read the New York Times Review of DarkBlueAlmostBlack