I am trying to automate getting a certain report from a web service my company uses. I've been using the Mechanize gem, and I was able to get other reports from the same service using it.
When I submit the form that generates the report, all I get back in response is headers of the CSV. It should be returning more than that, obviously.
I've used the Chrome Dev Tools to see what the expected values for each field are, and I've mimicked them. No matter what I try, though, I just can't get the service to return the expected values.
What should I try? What might I be doing wrong?
Edit: Code in question
#loginpage = 'service_uri'
agent = Mechanize.new
login_page = agent.get #loginpage
login_form = login_page.form
email_field = login_form.field_with(name: "Email")
password_field = login_form.field_with(name: "Password")
email_field.value = 'service_login'
password_field.value = 'service_password'
page = login_form.submit
transaction_page = page.link_with(text: 'Transaction History').click
transaction_form = transaction_page.form_with(action: "/reports/transactionhistory/transactionreportexport")
transaction_form['IncludeSupplier'] = "false"
transaction_form['IncludeBrand'] = "false"
transaction_form['IncludeClassification'] = "false"
transaction_form['IncludeAttributes'] = "false"
transaction_form['IncludeScannedCode'] = "false"
transaction_form['Reason'] = ""
transaction_form['Type'] = "AddItem"
transaction_form['WarehouseId'] = "0"
transaction_form['UserLocaleInfo.Locale'] = "en-US"
transaction_form['UserLocaleInfo.TimeZoneOffset'] = "-360"
dateToday = Date.today-2
dateTomorrow = Date.today-1
transaction_form['StartDate'] = "\"#{dateToday.to_s}-T06:00:00.000Z\""
transaction_form['EndDate'] = "\"#{dateTomorrow.to_s}-T05:59:59.999Z\""
transaction_form.submit
Related
I am wanting only certain servers to be able to use this feature shown below.
I want to know if there is a way to make it so only certain server ids can use this command.
#bot.command(pass_context = True)
async def shittymeme(ctx):
api = 'https://api.imgflip.com/get_memes'
response = requests.get(api)
url = random.choice(response.json()['data']['memes'])
url = url['url']
await bot.say( embed = discord.Embed(color = 0x0072ff, title = "Here you go").set_image(url = url))
Assuming you have a whitelist of server ids, you can take advantage of the Checks feature built into the commands extension.
whitelist = ["id1", "id2"]
def is_in_server_list(server_list):
def predicate(ctx):
return ctx.message.server.id in server_list
return commands.check(predicate)
#bot.command(pass_context = True)
#is_in_server_list(whitelist)
async def shittymeme(ctx):
api = 'https://api.imgflip.com/get_memes'
response = requests.get(api)
url = random.choice(response.json()['data']['memes'])
url = url['url']
await bot.say( embed = discord.Embed(color = 0x0072ff, title = "Here you go").set_image(url = url))
i'd like to make a call to rally rest api via ruby toolkit to get all workspaces for a subscription, like so:
query = RallyAPI::RallyQuery.new()
query.type = "workspace"
query.fetch = "ObjectID,Name"
query.project_scope_up = false
query.project_scope_down = true
query.order = "Name Asc"
query.query_string = ""
errors = query.validate()
findResults = #connection.find query
but this call apparently only returns the default workspace.
i have semi-successfully been able to navigate to the list of all workspaces when navigating thru the Subscription object, but i would prefer to follow a standard method of going after entity types as illustrated above.
is anyone aware of a way to get all workspaces via a direct query against the workspace type?
WS API calls are workspace scoped. You are correct that the code above will always return only the default workspace, and that workspaces can be accessed via Subscription object. Here is an example:
require 'rally_api'
#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "My Utility"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"
# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user#domain.com"
config[:password] = "secret"
config[:workspace] = "W1"
config[:project] = "P1"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()
rally = RallyAPI::RallyRestJson.new(config)
query = RallyAPI::RallyQuery.new()
query.type = :subscription
query.fetch = "Name,Workspaces,ObjectID"
results = rally.find(query)
sub = results.first
puts sub["Name"]
workspaces = sub["Workspaces"]
workspaces.each do |w|
puts "Name: #{w["Name"]}, OID: #{w["ObjectID"]}"
end
Whenever a query is intended to look outside of a default workspace, a non-default workspace can be specified. Here is an example of a query on defects outside of the default workspace:
query = RallyAPI::RallyQuery.new()
query.type = :defect
query.fetch = "Name,FormattedID,CreationDate,Owner,UserName"
query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.29/workspace/7777.js" } #optional
query.query_string = "(Owner.UserName = user#company.com)"
I think adding
query.workspace = "null"
will remove the workspace scoping that is applied by default to queries. I haven't tried this with the Ruby client, but I think it should work.
I have problem with crm 2011 caching. I don't need it, but I don't know how to disable it.
First I generate this:
CrmSvcUtil.exe
/codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization,
Microsoft.Xrm.Client.CodeGeneration" /out:Outputcs
/url:https://crmaddress/XRMServices/2011/Organization.svc
/username:usr/password:pw
/namespace:ns/serviceContextName:XrmServiceContext
then I have the following code:
private XrmServiceContext _crmService;
public CrmWS()
{
CrmConnection _connection = new CrmConnection();
_connection.ServiceUri = new Uri("https://url");
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential("1","2","3");
_connection.ClientCredentials = credentials;
_connection.ClientCredentials.UserName.UserName = "1";
_connection.ClientCredentials.UserName.Password = "2";
_crmService = new XrmServiceContext(_connection);
var l = _crmService.EntitySet.where(m => m.name == "a").ToList();
}
What should I do to turn off caching?
Specify the service in your configuration file:
<microsoft.xrm.client>
<services>
<add name="Xrm" type="Microsoft.Xrm.Client.Services.OrganizationService, Microsoft.Xrm.Client"/>
</services>
</microsoft.xrm.client>
Another bypass I found which can be used, its not perfect and people might give me bad reviews.
But you can always use a query which always changes with a random number or other random code:
Random r = new Random();
int rInt = r.Next(-100000000, 100000000);
var l = _crmService.EntitySet.where(m => m.name == "a" && m.name!=rInt.ToString()).ToList();
I have a Windows forms application (.NET 4.0) running with a Sql Server CE 3.5 database, which I access via an EF connection.
Here is my initial query, which returns two results:
var list = db.UserPresentation
.Select(up => new
{
UserPresentationID = up.UserPresentationID,
PresentationName = up.PresentationName,
DateRequested = up.DateRequested,
Edit = string.Empty,
Delete = string.Empty,
Download = string.Empty
})
.OrderByDescending(up => up.DateRequested)
.ToList();
Now I introduce an external variable and a where clause, and it returns zero results. If I run this same code in LinqPad, it returns 2 results.
int userID = 2;
// load list of user presentations
var list = db.UserPresentation
.Where(up => up.UserID == userID)
.Select(up => new
{
UserPresentationID = up.UserPresentationID,
PresentationName = up.PresentationName,
DateRequested = up.DateRequested,
Edit = string.Empty,
Delete = string.Empty,
Download = string.Empty
})
.OrderByDescending(up => up.DateRequested)
.ToList();
Now I hardcode the userid inside the query, and it returns two results again:
var list = db.UserPresentation
.Where(up => up.UserID == 2)
.Select(up => new
{
UserPresentationID = up.UserPresentationID,
PresentationName = up.PresentationName,
DateRequested = up.DateRequested,
Edit = string.Empty,
Delete = string.Empty,
Download = string.Empty
})
.OrderByDescending(up => up.DateRequested)
.ToList();
I'm really stumped. Any idea what's going on here?
Is UserID nullable?
If so be sure to do .Where(up => up.UserID.HasValue && up.UserID.Value == userID)
I had something similar with a nullable datetime once
Have you tried assigning the same hard coded value inside your variable? My guess is that the value in your variable is not found among your data, that is if you are sure that the variable name is correct.
I am trying to set up a web service to Celltrust's SMS Gateway. I have their SDK and I'm trying to use soap4r to create the custom headers that it needs. I'm not sure exactly what I need to do to get it in their format, since they don't provide me with an actual XML document showing what they need; all they say is that in the header you need to give a Username and Password.
Given the following PHP example code, how would I do this in Ruby?
$URN = "urn:notify.soap.primemessage.com";
$WSDL="http://pmgateway.net/pmws/services/TxTMessageService?wsdl";
//SOAP elements (don’t edit, and case sensitive!)
$CTUSERNAME = "Username";
$CTPASSWORD = "Password";
$CTNICKNAME = "nickname";
$DESTINATION = "destination";
$MESSAGE = "message";
$USER_ID = "USERNAME"; //your username at CellTrust
$NICKNAME = "NICKNAME"; //your nickname at Celltrust
$PASSWORD = "PASSWORD"; //your password at Celltrust
//create user and password SOAP header elements
$UserHdr = new SoapHeader( $URN, $CTUSERNAME, $USER_ID, false);
$PassHdr = new SoapHeader( $URN, $CTPASSWORD, $PASSWORD, false);
// call the method here
I've created a derivative class of SOAP::Header::SimpleHandler. What I'm not sure of is whether I need to specify the namespace twice (once for Username, once for Password) or how it is being generated. The documentation doesn't give any name for the namespace and I'm not sure how to do the call to "new SoapHeader" in Ruby properly.
Can anyone help me with this?
You need to create a subclass of SOAP::Header::SimpleHandler, as you mention:
class MyHandler < SOAP::Header::SimpleHandler
def initialize(namespace, name, value)
super(XSD::QName.new(namespace, name))
#value = value
end
def on_simple_outbound
#value
end
end
Then just do:
namespace = 'INSERT_NAMESPACE_URL_HERE'
# 'driver' below is the Soap4R driver for the service
driver.headerhandler << MyHandler.new(namespace, 'Username', 'INSERT_USERNAME_HERE')
driver.headerhandler << MyHandler.new(namespace, 'Password', 'INSERT_PASSWORD_HERE')