Comments (17)
You found another bug! I have committed a fix.
This list could actually be implemented as an iterator, where you loop over the content. That would allow huge result-sets. I have implemented that for one project, and been thinking about doing it in a more general fashion. If I get time in the near future, I'll see if I can use this movie API as one of the examples for such a general feature.
Thank you for digging out these bugs btw. If this was a commercial project there would have been a QA person spending considerable time figuring out how to crash the library - but with free, open source, I have to relay on my own imagination and real life cases reported by users.
from restc-cpp.
I don't really understand why these services keeps using OAuth. It's been broken (insecure) for a long time.
Anyway, using it requires cryptographic signing of headers and content in a very specific way. I think it should be done by restc-cpp as the process is complex and will take time to comprehend an implement. It's documented here: https://developer.twitter.com/en/docs/basics/authentication/guides/authorizing-a-request
The general OAuth 1.0 protocol is documented here: https://oauth.net/core/1.0/#anchor9
I don't have time to implement this right away, but I'll put it on my list.
from restc-cpp.
I'll have a look at it
from restc-cpp.
The url you provide will be encoded, and that will prevent the server from decoding your authentication token.
Try
SerializeFromJson(movie,
RequestBuilder(ctx)
.Get("http://api.themoviedb.org/3/search/movie")
.Argument("api_key", "30ac911b5a4841e65d905a53b31396ae")
.Argument("query", "Jack+Reacher")
.Header("X-Client", "RESTC_CPP")
.Header("X-Client-Purpose", "Testing")
.Execute());
The Argument() functions will make sure that the arguments are sent correctly.
You should 'git pull' restc-cpp, as I found and fixed a bug wen I checked this.
You may also want to get a new authentication token :)
from restc-cpp.
I have pulled and installed the restc-cpp library and used the code above. However, I am getting an error from SerializeJson.
Assertion failed: (false), function DoRecurseToMember, file /usr/local/include/restc-cpp/SerializeJson.h, line 704.
Edit: It is due to me trying to add the struct of results and it seems to be the wrong way of adding it.
struct Movie {
int page = 0;
int total_results = 0;
int total_pages = 0;
// string results = {}; //this is causing the issue
};
BOOST_FUSION_ADAPT_STRUCT(
Movie,
(int, page)
(int, total_results)
(int, total_pages)
// (string, results) //this is causing the issue
)
This is what I have for now:
struct Movie {
int page = 0;
int total_results = 0;
int total_pages = 0;
union results {
struct {
int vote_count;
int id;
bool video;
string title;
string popularity;
string poster_path;
string original_language;
string original_title;
string overview;
string release_date;
};
};
};
but I am not sure how to edit
BOOST_FUSION_ADAPT_STRUCT(
Movie,
(int, page)
(int, total_results)
(int, total_pages)
// (string, results)
)
from restc-cpp.
I would put the results in a structure and then and then add it as:
struct Movie {
int page = 0;
int total_results = 0;
int total_pages = 0;
std::vector<Results> results;
}
BOOST_FUSION_ADAPT_STRUCT(
Movie,
(int, page)
(int, total_results)
(int, total_pages)
(std::vector<Results>, results)
)
Make sure that Movie has the same member, as you map directly from C++ data-type and name.
You can have a look at this header to see some more complex mappings.
from restc-cpp.
I am getting Process finished with exit code 11 from this
struct Results {
int vote_count= 0;
int id= 0;
bool video;
double vote_average;
string title;
double popularity;
string poster_path;
string original_language;
string original_title;
bool adult;
string overview;
string release_date;
};
struct Movie {
int page = 0;
int total_results = 0;
int total_pages = 0;
std::vector<Results> results;
};
BOOST_FUSION_ADAPT_STRUCT(
Movie,
(int, page)
(int, total_results)
(int, total_pages)
(std::vector<Results>, results)
)
from restc-cpp.
I'll take a look
from restc-cpp.
Since you are serializing Results, you need to declare that as well :)
BOOST_FUSION_ADAPT_STRUCT(
Results,
(int, vote_count)
(int, id)
(bool, video)
(double, vote_average)
(string, title)
(double, popularity)
(string, poster_path)
(string, original_language)
(string, original_title)
(bool, adult)
(string, overview)
(string, release_date)
)
I have committed an assert for that case, and a fix where restc-cpp needs to ignore an array (genre_ids). So you should 'git poll' before testing again.
from restc-cpp.
Awesome! Got it to work. Thank you very much. Really appreciate it. :D
from restc-cpp.
I tried querying other movies such as Titanic and Black Panther and got this exception.
Assertion failed: (current_name_.empty()), function DoKey, file /usr/local/include/restc-cpp/SerializeJson.h, line 1024.
from restc-cpp.
That's interesting.
Can you share with me the request URL's or the json payloads from this requests? (curl can give you the payload from the command-line).
from restc-cpp.
It is the same as above just that I changed .Argument("query", "Jack+Reacher") to .Argument("query", "titanic")
Edit: I realised it is because genre_ids and backdrop_path are not set in struct.
struct Results {
int vote_count= 0;
int id= 0;
bool video;
double vote_average;
string title;
double popularity;
string poster_path;
string original_language;
string original_title;
std::vector<int> genre_ids;
string backdrop_path;
bool adult;
string overview;
string release_date;
};
struct Movie {
int page = 0;
int total_results = 0;
int total_pages = 0;
std::vector<Results> results;
};
BOOST_FUSION_ADAPT_STRUCT(
Results,
(int, vote_count)
(int, id)
(bool, video)
(double, vote_average)
(string, title)
(double, popularity)
(string, poster_path)
(string, original_language)
(string, original_title)
(std::vector<int>, genre_ids)
(string, backdrop_path)
(bool, adult)
(string, overview)
(string, release_date)
)
BOOST_FUSION_ADAPT_STRUCT(
Movie,
(int, page)
(int, total_results)
(int, total_pages)
(std::vector<Results>, results)
)
I added genre_ids and backdrop_path in struct and it works for query of Jack+Reacher but not spiderman or titanic. It causes the error:
Assertion failed: (current_name_.empty()), function DoKey, file /usr/local/include/restc-cpp/SerializeJson.h, line 1024.
from restc-cpp.
I'll take a look at it tomorrow. It might be a bug.
from restc-cpp.
Did I declare the array genre_ids wrongly?
Update: It seems to work for batman but does not work for query of spiderman
Assertion failed: (current_name_.empty()), function DoKey, file /usr/local/include/restc-cpp/SerializeJson.h, line 1024.
from restc-cpp.
I can reproduce it. Trying to figure out what's triggering the error.
from restc-cpp.
Great! Really thankful that you made it work. I will be trying to get it to work with Twitter API next, to pull tweets from Twitter. Any idea how to authorize request on twitter API with this library?
It should work if I Add_Headers() the following for authentication?
OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1318622958", oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", oauth_version="1.0"
from restc-cpp.
Related Issues (20)
- Add SOCKS5 support
- Improve logging HOT 2
- Multi-thread race condition
- HTTPS_FUNCTIONAL_TESTS failing on Debian Stretch and Ununtu Xenial
- On Debian 11, ctest fails unless I use RESTC_CPP_TEST_DOCKER_ADDRESS to set the ip
- provide build package for MSVC via vcpkg HOT 3
- Socks5 and TLS handshake failures in Debian Jessie and Ubuntu Xenial HOT 1
- Testing with Ubuntu Jammy fails with an exception in Jenkins HOT 1
- Problem with Coinbase REST Api. HOT 4
- Parsing json array of arrays HOT 1
- Wrong link order in CMakeLists.txt
- Getting exception "Failed to connect (closed)" with simple example. HOT 6
- Make some new examples
- Treat the co-routine functor sent to `Process()` as noexcept
- Update documentation and examples for exception handling inside `RestClient::Process()`
- Investigate utstable test `ExampleWorkflow.SequentialRequests`
- Serialize data of type int which has value of 0 to json HOT 3
- "400 Bad Request" using simple Graph API call over https HOT 5
- can I pass parameters in RestClient->Process(fun)? HOT 1
- bug in parsing url including colon in path
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restc-cpp.