Shopify API Search Parameters - ruby

I'm trying to get all of my customers that don't accept marketing but nothing seems to be working that I'm trying.
ShopifyAPI::Customer.find(:all, :params => { accepts_marketing: false})
I'm using the shopify_api Ruby gem.

The search endpoint is a little different than the usual. As you point out, your issue has nothing to do with Rails. Instead, just provide the endpoint with a little more information and you'll be fine. Try this:
ShopifyAPI::Customer.all( from: :search, params: {q: "accepts_marketing:true"})
You can search on customer email, whatever you need when you specify the endpoint as search on the Customer.

Related

Get Wordpress posts by tag in Ruby

We have a Wordpress instance with the XML-RPC API enabled and a Ruby on Rails website we want to display Wordpress posts on. I need to get posts by "tag". Looking at Rubypress it seems as though I have to wp.getPosts and parse out the correct ones. This is inefficient as we add new posts and have to keep updating.
Is there a way to get posts from a Wordpress instance via the API by tag?
Thank you.
We solved this with the wp_api_client gem and using the tags?slug=TAG endpoint. e.g.
require 'wp_api_client'
WpApiClient.configure do |api_client|
api_client.endpoint = "yourwordpress.com/wp-json/wp/v2"
api_client.basic_auth = {username: username, password: password}
end
client = WpApiClient.get_client
client.get("tags?slug=#{tag_you_want}").each do |tag|
client.get("posts?tags=#{tag.id}")
end

Why can Gibbon Gem access API but can't listSubscribe()?

I'm trying to get mailchimp integrated with my ruby-on-rails app using the Gibbon gem.
I've successfully accessed the API. I tested it by getting a list of all my mailchimp lists. However, I'm running into problems with the listsubscribe method. I'm not getting any errors, it just isn't working at all.
I have the following code in the controller for the page where users sign up, after the user is made and their information can be accessed.
gb=Gibbon::API.new
gb.listSubscribe({:id => "the-id-for-list", :email_address => user.email, :update_existing => false, :double_optin => false, :send_welcome => true, :merge_vars => {'FNAME' => user.first_name, 'LNAME' => user.last_name, 'MERGE3' => user.subscription, 'MERGE4' => DateTime.now}})
It does nothing. I've tried playing around with the parameter phrasing (à la this post:How do you use the Gibbon Gem to automatically add subscribers to specific interest groups in MailChimp?) I've tried structuring it more like in this tutorial: http://www.leorodriguez.me/2011/08/subscribe-member-into-mailchimp-using.html
I have no idea what's going wrong. As I said before, other API calls are going through to MailChimp. Do you have any suggestions? Thank you in advance.
It turns out I had the code in the wrong place. I was not putting it where users were actually being created, but in the code to generate the view to ask users to sign up. Once I moved it to where the user was actually created, it worked fine.

REST Client Example in Ruby

Can anyone explain me with an example, by using REST Client to do GET/POST/PUT operations in a Rest web service?
In POST/PUT, using REST Client, need to pass the whole xml body to do
POST/PUT operations.
For example, Using REST Client
I need to get the content of a service using,
RESTClient.get(url)
POST an xml to an url:
RESTClient.post(url,entirexml)
PUT an xml to an URL:
RESTClient.put(url,entirexml)
DELETE using REST CLIENT.
Can anyone help me with examples for all the REST Client HTTP METHODS with example?
I need to send the whole XML along with namespace to a rest service using PUT/POST operations of REST Client.
If anyone have examples on this, kindly post then please.
require 'rest-client'
RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
RestClient.get 'http://example.com/resource'
xml = '<xml><foo>bar</foo><bar>foo</bar></xml>'
RestClient.post 'http://example.com/resource', xml , {:content_type => :xml}
RestClient.put 'http://example.com/resource', xml , {:content_type => :xml}
RestClient.delete 'http://example.com/resource'
See more examples and documentation at https://github.com/rest-client/rest-client
The Readme file at the git site for the rest-client gem has a whole bunch of examples of how to do requests, include parameters, etc.
I'd start with that.
If there are specific things that are not working, then it generally helps to post the code you've tried that you think SHOULD be working, and then it's usually easier for people to tell where you are going wrong.

Fetching signed_request in a Facebook App with Ruby/Sinatra and the Rest-Graph gem

I've built a Facebook app using Sinatra and the Rest-Graph gem. Now I would like to embed the app as an iframe tab in a Facebook Page.
To do that, I need to fetch data from the signed_request sent to my app by Facebook.
The Rest-Graph gem states the following feature on its Github page:
Utility to extract access_token and
check sig in cookies/signed_request
I couldn't find any documentation on how to use this "utility". Can you point me to some documentation or even better, give me an example on how this is used with Ruby/Sinatra?
Nearly all of the Graph API libraries that are available deal with signed_request in a similar way. Rest-Graph has a parse_signed_request method (Rest-Graph/lib/core.rb) that you can call in Sinatra.
I'm using Koala for this with Sinatra, and it works as advertised:
oauth = Koala::Facebook::OAuth.new(APP_ID, APP_CODE)
signed_request = oauth.parse_signed_request(params["signed_request"])
You get back a hash of the JSON object that Facebook posts:
{
"algorithm"=>"HMAC-SHA256",
"issued_at"=>1303883452,
"user"=>
{
"country"=>"us",
"locale"=>"en_US"
},
"user_id"=>"100002364226618"
}
rest-graph makes it pretty easy, too. Just tested this in a Sinatra app. Works perfectly:
rg = RestGraph.new( :app_id => APP_ID, :secret => APP_SECRET)
parsed_request = rg.parse_signed_request!(params["signed_request"])
Lemme know if that doesn't work for you.
I just got a response to this question from "cardinalblue", the developer of the Rest-Graph gem. This little example was exactly what I was looking for:
require 'sinatra'
require 'rest-graph'
app_id = '123'
secret = 'abc'
config = {:app_id => app_id,
:secret => secret}
post '/' do
rg = RestGraph.new(config)
rg.parse_signed_request!(params['signed_request'])
"#{rg.get('me').inspect.gsub('<', '<')}\n"
end
run Sinatra::Application
Sidenote: In case you're building something similar, please note the post '/' do. Facebook Pages fetch your page using a POST request instead of a GET.

Tagging a user in Open Graph API using Ruby

I have found some really sparse documentation about the options for posting to your feed.
I am trying to post to "/me/feed" and then include a user in that post. I am trying to re-create the way that you can now do #username in the Facebook Status box, but from the API instead.
Using the Ruby OAuth2 lib I to do the following.
OAuth2::AccessToken.new(FBOAuthClient,fb_token).post("/me/feed", :message => status)
Which is great, but I want to do something like:
OAuth2::AccessToken.new(FBOAuthClient,fb_token).post("/me/feed", :message => status, :to => FUID)
Is this possible?
Or can, I post directly with JSON?
Thanks,
Kent
there still seems to be an open bug preventing this. http://bugs.developers.facebook.net/show_bug.cgi?id=12074

Resources